Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.yammer.dropwizard.json;
  
 
 import java.util.List;
 import java.util.Map;
A factory class for com.fasterxml.jackson.databind.ObjectMapper.

By default, ObjectMapperFactory is configured to:

  • Allow both C-style line and block comments.
  • Not fail when encountering unknown properties.
  • Use snake_case for property names when encoding and decoding classes annotated with JsonSnakeCase.
  • Support Guava and Logback types.
 
 @SuppressWarnings("UnusedDeclaration")
 public class ObjectMapperFactory {
     private final List<Modulemodules;
     private final Map<MapperFeatureBooleanmapperFeatures;
     private final Map<JsonGenerator.FeatureBooleangeneratorFeatures;
     private final Map<JsonParser.FeatureBooleanparserFeatures;
     private final Map<JsonFactory.FeatureBooleanfactoryFeatures;
 
     private DateFormat dateFormat;
     private TypeResolverBuilder<?> defaultTyping;
     private FilterProvider filters;
     private Locale locale;
     private Map<Class<?>, Class<?>> mixinAnnotations;
     private JsonNodeFactory nodeFactory;
     private SubtypeResolver subtypeResolver;
     private TimeZone timeZone;
     private TypeFactory typeFactory;
     private VisibilityChecker<?> visibilityChecker;


    
Create a new ObjectMapperFactory.
 
     public ObjectMapperFactory() {
         this. = Lists.newArrayList();
         this. = Maps.newHashMap();
         this. = Maps.newHashMap();
         this. = Maps.newHashMap();
         this. = Maps.newHashMap();
         this. = Maps.newHashMap();
         this. = Maps.newHashMap();
         this. = Maps.newLinkedHashMap();
 
 
 
         registerModule(new GuavaModule());
         registerModule(new LogbackModule());
         registerModule(new GuavaExtrasModule());
         registerModule(new JodaModule());
     }
 
         return ;
     }
 
    public void setAnnotationIntrospector(AnnotationIntrospector annotationIntrospector) {
        this. = annotationIntrospector;
    }
    public DateFormat getDateFormat() {
        return ;
    }
    public void setDateFormat(DateFormat dateFormat) {
        this. = dateFormat;
    }
    public TypeResolverBuilder<?> getDefaultTyping() {
        return ;
    }
    public void setDefaultTyping(TypeResolverBuilder<?> defaultTyping) {
        this. = defaultTyping;
    }
    public FilterProvider getFilters() {
        return ;
    }
    public void setFilters(FilterProvider filters) {
        this. = filters;
    }
        return ;
    }
    public void setHandlerInstantiator(HandlerInstantiator handlerInstantiator) {
        this. = handlerInstantiator;
    }
        return ;
    }
    public void setInjectableValues(InjectableValues injectableValues) {
        this. = injectableValues;
    }
    public Locale getLocale() {
        return ;
    }
    public void setLocale(Locale locale) {
        this. = locale;
    }
    public Map<Class<?>, Class<?>> getMixinAnnotations() {
        return ;
    }
    public void setMixinAnnotations(Map<Class<?>, Class<?>> mixinAnnotations) {
        this. = mixinAnnotations;
    }
    public JsonNodeFactory getNodeFactory() {
        return ;
    }
    public void setNodeFactory(JsonNodeFactory nodeFactory) {
        this. = nodeFactory;
    }
        return ;
    }
    public void setPropertyNamingStrategy(PropertyNamingStrategy propertyNamingStrategy) {
        this. = propertyNamingStrategy;
    }
        return ;
    }
    public void setSerializationInclusion(JsonInclude.Include serializationInclusion) {
        this. = serializationInclusion;
    }
        return ;
    }
    public void setSerializerFactory(SerializerFactory serializerFactory) {
        this. = serializerFactory;
    }
        return ;
    }
    public void setSerializerProvider(DefaultSerializerProvider serializerProvider) {
        this. = serializerProvider;
    }
        return ;
    }
    public void setSubtypeResolver(SubtypeResolver subtypeResolver) {
        this. = subtypeResolver;
    }
    public TimeZone getTimeZone() {
        return ;
    }
    public void setTimeZone(TimeZone timeZone) {
        this. = timeZone;
    }
    public TypeFactory getTypeFactory() {
        return ;
    }
    public void setTypeFactory(TypeFactory typeFactory) {
        this. = typeFactory;
    }
        return .get(accessor);
    }
    public void setVisibilityRules(PropertyAccessor accessorJsonAutoDetect.Visibility visibility) {
        .put(accessorvisibility);
    }
        return ;
    }
    public void setVisibilityChecker(VisibilityChecker<?> visibilityChecker) {
        this. = visibilityChecker;
    }

    
Registers a module that can extend functionality provided by this class; for example, by adding providers for custom serializers and deserializers.

    public void registerModule(Module module) {
        .add(module);
    }

    
Returns true if the given com.fasterxml.jackson.databind.MapperFeature is enabled.

Parameters:
feature a given feature
Returns:
true if feature is enabled
See also:
com.fasterxml.jackson.databind.ObjectMapper.isEnabled(com.fasterxml.jackson.databind.MapperFeature)
    public boolean isEnabled(MapperFeature feature) {
        final Boolean enabled = .get(feature);
        if (enabled != null) {
            return enabled;
        }
        return feature.enabledByDefault();
    }

    
    public void enable(MapperFeature... features) {
        for (MapperFeature feature : features) {
            .put(feature.);
        }
    }

    
    public void disable(MapperFeature... features) {
        for (MapperFeature feature : features) {
            .put(feature.);
        }
    }

    
Returns true if the given com.fasterxml.jackson.databind.DeserializationFeature is enabled.

Parameters:
feature a given feature
Returns:
true if feature is enabled
See also:
com.fasterxml.jackson.databind.ObjectMapper.isEnabled(com.fasterxml.jackson.databind.DeserializationFeature)
    public boolean isEnabled(DeserializationFeature feature) {
        final Boolean enabled = .get(feature);
        if (enabled != null) {
            return enabled;
        }
        return feature.enabledByDefault();
    }

    
    public void enable(DeserializationFeature... features) {
        for (DeserializationFeature feature : features) {
            .put(feature.);
        }
    }

    
    public void disable(DeserializationFeature... features) {
        for (DeserializationFeature feature : features) {
            .put(feature.);
        }
    }

    
Returns true if the given com.fasterxml.jackson.databind.SerializationFeature is enabled.

Parameters:
feature a given feature
Returns:
true if feature is enabled
See also:
com.fasterxml.jackson.databind.ObjectMapper.isEnabled(com.fasterxml.jackson.databind.SerializationFeature)
    public boolean isEnabled(SerializationFeature feature) {
        final Boolean enabled = .get(feature);
        if (enabled != null) {
            return enabled;
        }
        return feature.enabledByDefault();
    }

    
    public void enable(SerializationFeature... features) {
        for (SerializationFeature feature : features) {
            .put(feature.);
        }
    }

    
    public void disable(SerializationFeature... features) {
        for (SerializationFeature feature : features) {
            .put(feature.);
        }
    }

    
Returns true if the given com.fasterxml.jackson.core.JsonGenerator.Feature is enabled.

Parameters:
feature a given feature
Returns:
true if feature is enabled
See also:
com.fasterxml.jackson.databind.ObjectMapper.isEnabled(com.fasterxml.jackson.core.JsonGenerator.Feature)
    public boolean isEnabled(JsonGenerator.Feature feature) {
        final Boolean enabled = .get(feature);
        if (enabled != null) {
            return enabled;
        }
        return feature.enabledByDefault();
    }

    
    public void enable(JsonGenerator.Feature... features) {
        for (JsonGenerator.Feature feature : features) {
            .put(feature.);
        }
    }

    
    public void disable(JsonGenerator.Feature... features) {
        for (JsonGenerator.Feature feature : features) {
            .put(feature.);
        }
    }

    
Returns true if the given com.fasterxml.jackson.core.JsonParser.Feature is enabled.

Parameters:
feature a given feature
Returns:
true if feature is enabled
See also:
com.fasterxml.jackson.databind.ObjectMapper.isEnabled(com.fasterxml.jackson.core.JsonParser.Feature)
    public boolean isEnabled(JsonParser.Feature feature) {
        final Boolean enabled = .get(feature);
        if (enabled != null) {
            return enabled;
        }
        return feature.enabledByDefault();
    }

    
    public void enable(JsonParser.Feature... features) {
        for (JsonParser.Feature feature : features) {
            .put(feature.);
        }
    }

    
    public void disable(JsonParser.Feature... features) {
        for (JsonParser.Feature feature : features) {
            .put(feature.);
        }
    }

    
Returns true if the given com.fasterxml.jackson.core.JsonFactory.Feature is enabled.

Parameters:
feature a given feature
Returns:
true if feature is enabled
See also:
com.fasterxml.jackson.databind.ObjectMapper.isEnabled(com.fasterxml.jackson.core.JsonFactory.Feature)
    public boolean isEnabled(JsonFactory.Feature feature) {
        final Boolean enabled = .get(feature);
        if (enabled != null) {
            return enabled;
        }
        return feature.enabledByDefault();
    }

    
    public void enable(JsonFactory.Feature... features) {
        for (JsonFactory.Feature feature : features) {
            .put(feature.);
        }
    }

    
    public void disable(JsonFactory.Feature... features) {
        for (JsonFactory.Feature feature : features) {
            .put(feature.);
        }
    }

    
    public ObjectMapper build(JsonFactory factory) {
        final ObjectMapper mapper = new ObjectMapper(factory);
        for (Module module : ) {
            mapper.registerModule(module);
        }
        for (Map.Entry<MapperFeatureBooleanentry : .entrySet()) {
            mapper.configure(entry.getKey(), entry.getValue());
        }
            mapper.configure(entry.getKey(), entry.getValue());
        }
        for (Map.Entry<SerializationFeatureBooleanentry : .entrySet()) {
            mapper.configure(entry.getKey(), entry.getValue());
        }
        for (Map.Entry<JsonGenerator.FeatureBooleanentry : .entrySet()) {
            mapper.getFactory().configure(entry.getKey(), entry.getValue());
        }
        for (Map.Entry<JsonParser.FeatureBooleanentry : .entrySet()) {
            mapper.getFactory().configure(entry.getKey(), entry.getValue());
        }
        for (Map.Entry<JsonFactory.FeatureBooleanentry : .entrySet()) {
            mapper.getFactory().configure(entry.getKey(), entry.getValue());
        }
        if ( != null) {
            mapper.setAnnotationIntrospector();
        }
        if ( != null) {
            mapper.setDateFormat();
        }
        if ( != null) {
            mapper.setDefaultTyping();
        }
        if ( != null) {
            mapper.setFilters();
        }
        if ( != null) {
            mapper.setHandlerInstantiator();
        }
        if ( != null) {
            mapper.setInjectableValues();
        }
        if ( != null) {
            mapper.setLocale();
        }
        if ( != null) {
            mapper.setMixInAnnotations();
        }
        if ( != null) {
            mapper.setNodeFactory();
        }
        if ( != null) {
            mapper.setPropertyNamingStrategy();
        }
        if ( != null) {
            mapper.setSerializationInclusion();
        }
        if ( != null) {
            mapper.setSerializerFactory();
        }
        if ( != null) {
            mapper.setSerializerProvider();
        }
        if ( != null) {
            mapper.setSubtypeResolver();
        }
        if ( != null) {
            mapper.setTimeZone();
        }
        if ( != null) {
            mapper.setTypeFactory();
        }
            mapper.setVisibility(rule.getKey(), rule.getValue());
        }
        if ( != null) {
            mapper.setVisibilityChecker();
        }
        return mapper;
    }

    
    public ObjectMapper build() {
        return build(new JsonFactory());
    }

    
Creates a copy of this.

Returns:
a copy of this
    public ObjectMapperFactory copy() {
        final ObjectMapperFactory factory = new ObjectMapperFactory();
        factory.modules.addAll();
        factory.mapperFeatures.putAll();
        factory.deserializationFeatures.putAll();
        factory.serializationFeatures.putAll();
        factory.generatorFeatures.putAll();
        factory.parserFeatures.putAll();
        factory.factoryFeatures.putAll();
        factory.visibilityRules.putAll();
        factory.annotationIntrospector = ;
        factory.dateFormat = ;
        factory.defaultTyping = ;
        factory.filters = ;
        factory.handlerInstantiator = ;
        factory.injectableValues = ;
        factory.locale = ;
        factory.mixinAnnotations = ;
        factory.nodeFactory = ;
        factory.propertyNamingStrategy = ;
        factory.serializationInclusion = ;
        factory.serializerFactory = ;
        factory.serializerProvider = ;
        factory.subtypeResolver = ;
        factory.timeZone = ;
        factory.visibilityChecker = ;
        return factory;
    }
New to GrepCode? Check out our FAQ X