Search in sources :

Example 6 with JacksonAnnotationIntrospector

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

the class SyncUtils method getObjectMapper.

public ObjectMapper getObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory());
    AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary);
    mapper.setAnnotationIntrospector(pair);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    // Filter specific things we do not want exported:
    SimpleFilterProvider filterProvider = new SimpleFilterProvider();
    filterProvider.setFailOnUnknownId(false);
    filterProvider = filterProvider.addFilter("EntitlementFilter", SimpleBeanPropertyFilter.serializeAllExcept("consumer"));
    mapper.setFilterProvider(filterProvider);
    mapper.registerModule(productCachedModule);
    if (config != null) {
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, config.getBoolean(ConfigProperties.FAIL_ON_UNKNOWN_IMPORT_PROPERTIES));
    }
    return mapper;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospectorPair(com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) 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 7 with JacksonAnnotationIntrospector

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

the class ArtifactoryHttpClient method createJsonFactory.

public JsonFactory createJsonFactory() {
    JsonFactory jsonFactory = new JsonFactory();
    ObjectMapper mapper = new ObjectMapper(jsonFactory);
    mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    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 8 with JacksonAnnotationIntrospector

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

the class AbstractEurekaJacksonCodec method bindAmazonInfoFilter.

private void bindAmazonInfoFilter(ObjectMapper mapper) {
    SimpleFilterProvider filters = new SimpleFilterProvider();
    final String filterName = "exclude-amazon-info-entries";
    mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {

        @Override
        public Object findFilterId(Annotated a) {
            if (Map.class.isAssignableFrom(a.getRawType())) {
                return filterName;
            }
            return super.findFilterId(a);
        }
    });
    filters.addFilter(filterName, new SimpleBeanPropertyFilter() {

        @Override
        protected boolean include(BeanPropertyWriter writer) {
            return true;
        }

        @Override
        protected boolean include(PropertyWriter writer) {
            return MINI_AMAZON_INFO_INCLUDE_KEYS.contains(writer.getName());
        }
    });
    mapper.setFilters(filters);
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) Annotated(com.fasterxml.jackson.databind.introspect.Annotated) SimpleBeanPropertyFilter(com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter) Map(java.util.Map) BeanPropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter) BeanPropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter) PropertyWriter(com.fasterxml.jackson.databind.ser.PropertyWriter)

Example 9 with JacksonAnnotationIntrospector

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

the class Util 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 10 with JacksonAnnotationIntrospector

use of com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector in project spring-framework by spring-projects.

the class Jackson2ObjectMapperBuilderTests method postConfigurer.

// gh-23017
@Test
void postConfigurer() {
    JacksonAnnotationIntrospector introspector1 = new JacksonAnnotationIntrospector();
    JacksonAnnotationIntrospector introspector2 = new JacksonAnnotationIntrospector();
    ObjectMapper mapper = Jackson2ObjectMapperBuilder.json().postConfigurer(m -> m.setAnnotationIntrospectors(introspector1, introspector2)).build();
    assertThat(mapper.getSerializationConfig().getAnnotationIntrospector()).isSameAs(introspector1);
    assertThat(mapper.getDeserializationConfig().getAnnotationIntrospector()).isSameAs(introspector2);
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) Module(com.fasterxml.jackson.databind.Module) Arrays(java.util.Arrays) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SimpleBeanPropertyFilter(com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Locale(java.util.Locale) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) Map(java.util.Map) JsonSerializer(com.fasterxml.jackson.databind.JsonSerializer) DeserializerFactoryConfig(com.fasterxml.jackson.databind.cfg.DeserializerFactoryConfig) XmlFactory(com.fasterxml.jackson.dataformat.xml.XmlFactory) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) Path(java.nio.file.Path) IntRange(kotlin.ranges.IntRange) NopAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector) TimeZone(java.util.TimeZone) Visibility(com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility) Version(com.fasterxml.jackson.core.Version) SerializerFactoryConfig(com.fasterxml.jackson.databind.cfg.SerializerFactoryConfig) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) Test(org.junit.jupiter.api.Test) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) BasicDeserializerFactory(com.fasterxml.jackson.databind.deser.BasicDeserializerFactory) BasicSerializerFactory(com.fasterxml.jackson.databind.ser.BasicSerializerFactory) Optional(java.util.Optional) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Serializers(com.fasterxml.jackson.databind.ser.Serializers) SimpleType(com.fasterxml.jackson.databind.type.SimpleType) CBORFactory(com.fasterxml.jackson.dataformat.cbor.CBORFactory) AnnotationIntrospectorPair(com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair) ArrayList(java.util.ArrayList) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) Deserializers(com.fasterxml.jackson.databind.deser.Deserializers) ClassSerializer(com.fasterxml.jackson.databind.ser.std.ClassSerializer) DateDeserializers(com.fasterxml.jackson.databind.deser.std.DateDeserializers) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) StreamSupport(java.util.stream.StreamSupport) PropertyAccessor(com.fasterxml.jackson.annotation.PropertyAccessor) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) PropertyNamingStrategy(com.fasterxml.jackson.databind.PropertyNamingStrategy) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) JsonParser(com.fasterxml.jackson.core.JsonParser) FatalBeanException(org.springframework.beans.FatalBeanException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleSerializers(com.fasterxml.jackson.databind.module.SimpleSerializers) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SmileFactory(com.fasterxml.jackson.dataformat.smile.SmileFactory) JsonFilter(com.fasterxml.jackson.annotation.JsonFilter) Paths(java.nio.file.Paths) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) Collections(java.util.Collections) NumberSerializer(com.fasterxml.jackson.databind.ser.std.NumberSerializer) StringUtils(org.springframework.util.StringUtils) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

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