Example usage for com.fasterxml.jackson.databind ObjectMapper enableDefaultTypingAsProperty

List of usage examples for com.fasterxml.jackson.databind ObjectMapper enableDefaultTypingAsProperty

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper enableDefaultTypingAsProperty.

Prototype

public ObjectMapper enableDefaultTypingAsProperty(DefaultTyping applicability, String propertyName) 

Source Link

Document

Method for enabling automatic inclusion of type information -- needed for proper deserialization of polymorphic types (unless types have been annotated with com.fasterxml.jackson.annotation.JsonTypeInfo ) -- using "As.PROPERTY" inclusion mechanism and specified property name to use for inclusion (default being "@class" since default type information always uses class name as type identifier)

Usage

From source file:org.nohope.jongo.JacksonProcessor.java

@Nonnull
private static ObjectMapper createPreConfiguredMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JodaModule());
    mapper.registerModule(new ColorModule());

    mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(AUTO_DETECT_GETTERS, false);
    mapper.configure(AUTO_DETECT_SETTERS, false);
    mapper.setSerializationInclusion(NON_NULL);
    mapper.setVisibilityChecker(VisibilityChecker.Std.defaultInstance().withFieldVisibility(ANY));

    mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.NON_FINAL,
            JsonTypeInfo.Id.CLASS.getDefaultPropertyName());

    final SimpleModule module = new SimpleModule("jongo", Version.unknownVersion());
    module.addKeySerializer(Object.class, ComplexKeySerializer.S_OBJECT);
    module.addKeyDeserializer(String.class, ComplexKeyDeserializer.S_OBJECT);
    module.addKeyDeserializer(Object.class, ComplexKeyDeserializer.S_OBJECT);

    //addBSONTypeSerializers(module);

    mapper.registerModule(module);/*from   w w  w  .  j  a v  a 2 s . c  o m*/
    return mapper;
}