Android Open Source - Async-Http-lib-with-Parsing-for-Android Jackson Object Mapper Holder






From Project

Back to project page Async-Http-lib-with-Parsing-for-Android.

License

The source code is released under:

Apache License

If you think the Android project Async-Http-lib-with-Parsing-for-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.cognizant.http.jackson;
//w  w  w  . j  av a2s  . c o m
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Creates and initializes the common {@link ObjectMapper} for the
 * {@link JsonResponseMappingNetworkServiceCall}s. Since the
 * {@link ObjectMapper} is thread-safe as long as its not being configured, this
 * class will handle its setup and users should not modify its configuration.
 */
public class JacksonObjectMapperHolder {

    static final ObjectMapper mapper = createObjectMapper();

    /**
     * 
     * @return Returns a jackson mapper used to deserialize an incoming error
     *         response with a JSON body
     */
    public static ObjectMapper getMapper() {
        return mapper;
    }

    /**
     * Create the Jackson Mapper
     * 
     * @return ObjectMapper Jackson Mapper
     */
    private static ObjectMapper createObjectMapper() {
        return new ObjectMapper().disable(MapperFeature.AUTO_DETECT_GETTERS)
                .disable(MapperFeature.AUTO_DETECT_SETTERS)
                .configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true)
                .setSerializationInclusion(JsonInclude.Include.NON_NULL)
                .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    }

    /**
     * Singleton Class so prevent the making of the class.
     */
    private JacksonObjectMapperHolder() {
        throw new UnsupportedOperationException(
                "This class is non-instantiable");
    }

}




Java Source Code List

com.cognizant.http.HttpConnection.java
com.cognizant.http.HttpConstant.java
com.cognizant.http.Request.java
com.cognizant.http.ServiceBean.java
com.cognizant.http.ServiceCallAsyncTask.java
com.cognizant.http.ServiceCall.java
com.cognizant.http.jackson.JacksonObjectMapperHolder.java
com.cognizant.http.listeners.ResponseEventListener.java
com.cognizant.http.utils.HTTPUtil.java
com.cognizant.http.utils.NetworkAccessUtil.java
com.cognizant.http.utils.NoNetworkAvailableException.java