Search in sources :

Example 11 with JacksonAnnotationIntrospector

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

the class Util method createJsonMapper.

/**
 * Creates json mapper.
 *
 * @return json mapper
 */
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.setAnnotationIntrospector(pair);
    return mapper;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector)

Example 12 with JacksonAnnotationIntrospector

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

the class TestVersions method testMapperVersions.

public void testMapperVersions() {
    ObjectMapper mapper = new ObjectMapper();
    assertVersion(mapper);
    assertVersion(mapper.reader());
    assertVersion(mapper.writer());
    assertVersion(new JacksonAnnotationIntrospector());
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 13 with JacksonAnnotationIntrospector

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

the class SerializerUtils method getMapper.

public static ObjectMapper getMapper() {
    ObjectMapper mapper = new ObjectMapper();
    AnnotationIntrospector aipair = new AnnotationIntrospectorPair(new JaxbAnnotationIntrospector(), new JacksonAnnotationIntrospector());
    mapper.setAnnotationIntrospector(aipair);
    // REMOVE: mapper.configure(SerializationConfig.Feature.USE_ANNOTATIONS, true);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return mapper;
}
Also used : AnnotationIntrospectorPair(com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair) 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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector)

Example 14 with JacksonAnnotationIntrospector

use of com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector in project endpoints-java by cloudendpoints.

the class ObjectMapperUtil method createStandardObjectMapper.

/**
 * Creates an Endpoints standard object mapper that allows unquoted field names and unknown
 * properties.
 *
 * Note on unknown properties: When Apiary FE supports a strict mode where properties
 * are checked against the schema, BE can just ignore unknown properties.  This way, FE does
 * not need to filter out everything that the BE doesn't understand.  Before that's done,
 * a property name with a typo in it, for example, will just be ignored by the BE.
 */
public static ObjectMapper createStandardObjectMapper(ApiSerializationConfig config) {
    ObjectMapper objectMapper = new ObjectMapper().configure(JsonParser.Feature.ALLOW_COMMENTS, true).configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true).configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).setBase64Variant(Base64Variants.MODIFIED_FOR_URL).setSerializerFactory(BeanSerializerFactory.instance.withSerializerModifier(new DeepEmptyCheckingModifier()));
    AnnotationIntrospector pair = AnnotationIntrospector.pair(new ApiAnnotationIntrospector(config), new JacksonAnnotationIntrospector());
    objectMapper.setAnnotationIntrospector(pair);
    return objectMapper;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) ApiAnnotationIntrospector(com.google.api.server.spi.config.annotationreader.ApiAnnotationIntrospector) ApiAnnotationIntrospector(com.google.api.server.spi.config.annotationreader.ApiAnnotationIntrospector) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 15 with JacksonAnnotationIntrospector

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

the class JsonSerializer method toJSON.

public String toJSON(T object) throws IOException {
    JsonFactory jsonFactory = new JsonFactory();
    ObjectMapper mapper = new ObjectMapper(jsonFactory);
    mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    jsonFactory.setCodec(mapper);
    StringWriter writer = new StringWriter();
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer);
    jsonGenerator.useDefaultPrettyPrinter();
    jsonGenerator.writeObject(object);
    return writer.getBuffer().toString();
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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