Search in sources :

Example 16 with JacksonAnnotationIntrospector

use of com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector in project build-info by JFrogDev.

the class BuildInfoExtractorUtils method createJsonFactory.

// TODO: [by YS] duplicates ArtifactoryBuildInfoClient. The client should depend on this module
// TODO: [by yl] introduce a commons module for common impl and also move PropertyUtils there
private static JsonFactory createJsonFactory() {
    JsonFactory jsonFactory = new JsonFactory();
    ObjectMapper mapper = new ObjectMapper(jsonFactory);
    mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    jsonFactory.setCodec(mapper);
    return jsonFactory;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 17 with JacksonAnnotationIntrospector

use of com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector in project oxAuth by GluuFederation.

the class ServerUtil method createJsonMapper.

public static ObjectMapper createJsonMapper() {
    final AnnotationIntrospector jaxb = new JaxbAnnotationIntrospector();
    final AnnotationIntrospector jackson = new JacksonAnnotationIntrospector();
    final AnnotationIntrospector pair = AnnotationIntrospector.pair(jackson, jaxb);
    final ObjectMapper mapper = new ObjectMapper();
    mapper.getDeserializationConfig().with(pair);
    mapper.getSerializationConfig().with(pair);
    return mapper;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 18 with JacksonAnnotationIntrospector

use of com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector in project platformlayer by platformlayer.

the class JsonHelper method buildObjectMapper.

public static ObjectMapper buildObjectMapper(TypeFactory typeFactory, boolean formatted) {
    ObjectMapper mapper = new ObjectMapper();
    if (typeFactory == null) {
        typeFactory = TypeFactory.defaultInstance();
    }
    if (formatted) {
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
    }
    // Favor JAXB annotations
    AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(typeFactory);
    AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
    AnnotationIntrospector introspector = new AnnotationIntrospectorPair(jaxbIntrospector, jacksonIntrospector);
    mapper.setAnnotationIntrospector(introspector);
    return mapper;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospectorPair(com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector)

Example 19 with JacksonAnnotationIntrospector

use of com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector in project zm-mailbox by Zimbra.

the class JaxbToJsonTest method getSimpleJsonJaxbMapper.

public ObjectMapper getSimpleJsonJaxbMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(new JacksonAnnotationIntrospector(), new JaxbAnnotationIntrospector()));
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    return mapper;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector)

Example 20 with JacksonAnnotationIntrospector

use of com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector in project oap by oaplatform.

the class Binder method initialize.

private static ObjectMapper initialize(ObjectMapper mapper, boolean defaultTyping, boolean nonNullInclusion, boolean skipInputNulls) {
    if (mapper instanceof XmlMapper) {
        ((XmlMapper) mapper).setDefaultUseWrapper(false);
        ((XmlMapper) mapper).configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
    }
    AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
    mapper.getDeserializationConfig().with(introspector);
    mapper.getSerializationConfig().with(introspector);
    mapper.registerModule(new AfterburnerModule());
    mapper.registerModule(new Jdk8Module().configureAbsentsAsNulls(true));
    mapper.registerModule(new JodaModule());
    mapper.registerModule(new ExtModule());
    mapper.registerModule(new JavaTimeModule());
    mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.DEFAULT));
    mapper.enable(DeserializationFeature.USE_LONG_FOR_INTS);
    mapper.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    mapper.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
    mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
    mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    // todo remove after kernel cleanup
    mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
    if (skipInputNulls)
        mapper.setDefaultSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SKIP));
    if (!nonNullInclusion)
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    modules.forEach(mapper::registerModule);
    if (defaultTyping)
        mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
    return mapper;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ParameterNamesModule(com.fasterxml.jackson.module.paramnames.ParameterNamesModule) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) ExtModule(oap.json.ext.ExtModule)

Aggregations

JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)20 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)14 AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)11 JaxbAnnotationIntrospector (com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector)9 AnnotationIntrospectorPair (com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair)5 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)4 JsonFactory (com.fasterxml.jackson.core.JsonFactory)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 Annotated (com.fasterxml.jackson.databind.introspect.Annotated)2 AnnotatedClass (com.fasterxml.jackson.databind.introspect.AnnotatedClass)2 SimpleBeanPropertyFilter (com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Map (java.util.Map)2 Visibility (com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility)1 JsonFilter (com.fasterxml.jackson.annotation.JsonFilter)1 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 PropertyAccessor (com.fasterxml.jackson.annotation.PropertyAccessor)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Version (com.fasterxml.jackson.core.Version)1