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

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

Introduction

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

Prototype

public ObjectMapper enableDefaultTyping(DefaultTyping applicability, JsonTypeInfo.As includeAs) 

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 ).

Usage

From source file:com.marklogic.client.test.JacksonDatabindTest.java

@BeforeClass
public static void beforeClass() {
    // demonstrate our ability to set advanced configuration on a mapper
    ObjectMapper mapper = new ObjectMapper();
    // in this case, we're saying wrap our serialization with the name of the pojo class
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_OBJECT);
    // register a JacksonDatabindHandleFactory ready to marshall any City object to/from json
    // this enables the writeAs method below
    DatabaseClientFactory.getHandleRegistry().register(JacksonDatabindHandle.newFactory(mapper, City.class));
    Common.connect();//from  w w  w . j a v  a  2  s . co  m
    //System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "debug");
}

From source file:org.springframework.batch.admin.domain.support.VariableTypeJackson2ObjectMapperFactoryBean.java

@Override
public ObjectMapper getObject() {
    ObjectMapper objectMapper = super.getObject();
    objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
    return objectMapper;
}

From source file:org.jasig.cas.util.AbstractJacksonBackedJsonSerializer.java

/**
 * Initialize object mapper.//w w  w .ja  v  a2s.c  o  m
 *
 * @return the object mapper
 */
protected ObjectMapper initializeObjectMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    mapper.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC);
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
    return mapper;
}

From source file:org.springframework.security.jackson2.SecurityJacksonModules.java

public static void enableDefaultTyping(ObjectMapper mapper) {
    if (!ObjectUtils.isEmpty(mapper)) {
        TypeResolverBuilder<?> typeBuilder = mapper.getDeserializationConfig().getDefaultTyper(null);
        if (ObjectUtils.isEmpty(typeBuilder)) {
            mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
        }/*from w  w w.  j  av a 2 s  .co  m*/
    }
}