Search in sources :

Example 1 with Annotated

use of com.fasterxml.jackson.databind.introspect.Annotated 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 2 with Annotated

use of com.fasterxml.jackson.databind.introspect.Annotated 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 3 with Annotated

use of com.fasterxml.jackson.databind.introspect.Annotated in project swagger-core by swagger-api.

the class ModelResolver method resolveSchemaMembers.

protected void resolveSchemaMembers(Schema schema, AnnotatedType annotatedType) {
    final JavaType type;
    if (annotatedType.getType() instanceof JavaType) {
        type = (JavaType) annotatedType.getType();
    } else {
        type = _mapper.constructType(annotatedType.getType());
    }
    final Annotation resolvedSchemaOrArrayAnnotation = AnnotationsUtils.mergeSchemaAnnotations(annotatedType.getCtxAnnotations(), type);
    final io.swagger.v3.oas.annotations.media.Schema schemaAnnotation = resolvedSchemaOrArrayAnnotation == null ? null : resolvedSchemaOrArrayAnnotation instanceof io.swagger.v3.oas.annotations.media.ArraySchema ? ((io.swagger.v3.oas.annotations.media.ArraySchema) resolvedSchemaOrArrayAnnotation).schema() : (io.swagger.v3.oas.annotations.media.Schema) resolvedSchemaOrArrayAnnotation;
    final BeanDescription beanDesc = _mapper.getSerializationConfig().introspect(type);
    Annotated a = beanDesc.getClassInfo();
    Annotation[] annotations = annotatedType.getCtxAnnotations();
    resolveSchemaMembers(schema, a, annotations, schemaAnnotation);
}
Also used : UUIDSchema(io.swagger.v3.oas.models.media.UUIDSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) Annotation(java.lang.annotation.Annotation) Annotated(com.fasterxml.jackson.databind.introspect.Annotated) JavaType(com.fasterxml.jackson.databind.JavaType) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema)

Aggregations

Annotated (com.fasterxml.jackson.databind.introspect.Annotated)3 JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)2 AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)1 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AnnotatedClass (com.fasterxml.jackson.databind.introspect.AnnotatedClass)1 AnnotatedField (com.fasterxml.jackson.databind.introspect.AnnotatedField)1 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)1 BeanPropertyWriter (com.fasterxml.jackson.databind.ser.BeanPropertyWriter)1 PropertyWriter (com.fasterxml.jackson.databind.ser.PropertyWriter)1 SimpleBeanPropertyFilter (com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter)1 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)1 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)1 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)1 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)1 MapSchema (io.swagger.v3.oas.models.media.MapSchema)1 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)1 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)1 Schema (io.swagger.v3.oas.models.media.Schema)1