Search in sources :

Example 1 with JacksonAnnotationIntrospector

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

the class MyObjectMapperProvider method createJaxbJacksonAnnotationIntrospector.

private static AnnotationIntrospector createJaxbJacksonAnnotationIntrospector() {
    final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
    return AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector);
}
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)

Example 2 with JacksonAnnotationIntrospector

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

the class FilteringJacksonJaxbJsonProvider method _configForWriting.

@Override
protected JsonEndpointConfig _configForWriting(final ObjectMapper mapper, final Annotation[] annotations, final Class<?> defaultView) {
    final AnnotationIntrospector customIntrospector = mapper.getSerializationConfig().getAnnotationIntrospector();
    // Set the custom (user) introspector to be the primary one.
    final ObjectMapper filteringMapper = mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(customIntrospector, new JacksonAnnotationIntrospector() {

        @Override
        public Object findFilterId(final Annotated a) {
            final Object filterId = super.findFilterId(a);
            if (filterId != null) {
                return filterId;
            }
            if (a instanceof AnnotatedMethod) {
                final Method method = ((AnnotatedMethod) a).getAnnotated();
                // Interested only in getters - trying to obtain "field" name from them.
                if (ReflectionHelper.isGetter(method)) {
                    return ReflectionHelper.getPropertyName(method);
                }
            }
            if (a instanceof AnnotatedField || a instanceof AnnotatedClass) {
                return a.getName();
            }
            return null;
        }
    }));
    return super._configForWriting(filteringMapper, annotations, defaultView);
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) Annotated(com.fasterxml.jackson.databind.introspect.Annotated) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) Method(java.lang.reflect.Method) AnnotatedField(com.fasterxml.jackson.databind.introspect.AnnotatedField) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with JacksonAnnotationIntrospector

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

the class TestJacksonAnnotationIntrospector method testJsonTypeResolver.

public void testJsonTypeResolver() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    JacksonAnnotationIntrospector ai = new JacksonAnnotationIntrospector();
    AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(TypeResolverBean.class, mapper.getSerializationConfig());
    JavaType baseType = TypeFactory.defaultInstance().constructType(TypeResolverBean.class);
    TypeResolverBuilder<?> rb = ai.findTypeResolver(mapper.getDeserializationConfig(), ac, baseType);
    assertNotNull(rb);
    assertSame(DummyBuilder.class, rb.getClass());
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass)

Example 4 with JacksonAnnotationIntrospector

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

the class FF4jCustomObjectMapper method createDefaultMapper.

/**
 * Custom ObjectMapper
 * @return
 *      target object mapper
 */
private static ObjectMapper createDefaultMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
    mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
    mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true);
    mapper.setDateFormat(new SimpleDateFormat("dd/MM/yyyy"));
    return mapper;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) SimpleDateFormat(java.text.SimpleDateFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with JacksonAnnotationIntrospector

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

the class JsonProvider method configureHateoasObjectMapper.

private void configureHateoasObjectMapper(ObjectMapper mapper, boolean indentJson) {
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    if (indentJson) {
        mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    }
    SimpleFilterProvider filterProvider = new SimpleFilterProvider();
    filterProvider = filterProvider.addFilter("ConsumerFilter", new MultiFilter(new HateoasBeanPropertyFilter(), new DynamicPropertyFilter()));
    filterProvider = filterProvider.addFilter("EntitlementFilter", new MultiFilter(new HateoasBeanPropertyFilter(), new DynamicPropertyFilter()));
    filterProvider = filterProvider.addFilter("OwnerFilter", new MultiFilter(new HateoasBeanPropertyFilter(), new DynamicPropertyFilter()));
    filterProvider = filterProvider.addFilter("GuestFilter", new MultiFilter(new HateoasBeanPropertyFilter(), new DynamicPropertyFilter()));
    filterProvider.setDefaultFilter(new DynamicPropertyFilter());
    filterProvider.setFailOnUnknownId(false);
    mapper.setFilterProvider(filterProvider);
    AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory());
    AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary);
    mapper.setAnnotationIntrospector(pair);
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospectorPair(com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) HateoasBeanPropertyFilter(org.candlepin.common.jackson.HateoasBeanPropertyFilter) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector) DynamicPropertyFilter(org.candlepin.common.jackson.DynamicPropertyFilter) MultiFilter(org.candlepin.common.jackson.MultiFilter) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector)

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