Search in sources :

Example 11 with AnnotationIntrospector

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

the class BasicClassIntrospector method collectPropertiesWithBuilder.

protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> config, JavaType type, MixInResolver r, boolean forSerialization) {
    boolean useAnnotations = config.isAnnotationProcessingEnabled();
    AnnotationIntrospector ai = useAnnotations ? config.getAnnotationIntrospector() : null;
    AnnotatedClass ac = AnnotatedClass.construct(type, config, r);
    JsonPOJOBuilder.Value builderConfig = (ai == null) ? null : ai.findPOJOBuilderConfig(ac);
    String mutatorPrefix = (builderConfig == null) ? JsonPOJOBuilder.DEFAULT_WITH_PREFIX : builderConfig.withPrefix;
    return constructPropertyCollector(config, ac, type, forSerialization, mutatorPrefix);
}
Also used : AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) JsonPOJOBuilder(com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder)

Example 12 with AnnotationIntrospector

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

the class ConcreteBeanPropertyBase method findPropertyFormat.

@Override
public JsonFormat.Value findPropertyFormat(MapperConfig<?> config, Class<?> baseType) {
    // 15-Apr-2016, tatu: Let's calculate lazily, retain; assumption being however that
    //    baseType is always the same
    JsonFormat.Value v = _propertyFormat;
    if (v == null) {
        JsonFormat.Value v1 = config.getDefaultPropertyFormat(baseType);
        JsonFormat.Value v2 = null;
        AnnotationIntrospector intr = config.getAnnotationIntrospector();
        if (intr != null) {
            AnnotatedMember member = getMember();
            if (member != null) {
                v2 = intr.findFormat(member);
            }
        }
        if (v1 == null) {
            v = (v2 == null) ? EMPTY_FORMAT : v2;
        } else {
            v = (v2 == null) ? v1 : v1.withOverrides(v2);
        }
        _propertyFormat = v;
    }
    return v;
}
Also used : JsonFormat(com.fasterxml.jackson.annotation.JsonFormat) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector)

Example 13 with AnnotationIntrospector

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

the class StdSubtypeResolver method collectAndResolveSubtypesByClass.

/*
    /**********************************************************
    /* Resolution by class (serialization)
    /**********************************************************
     */
@Override
public Collection<NamedType> collectAndResolveSubtypesByClass(MapperConfig<?> config, AnnotatedMember property, JavaType baseType) {
    final AnnotationIntrospector ai = config.getAnnotationIntrospector();
    // for backwards compatibility, must allow null here:
    Class<?> rawBase = (baseType == null) ? property.getRawType() : baseType.getRawClass();
    HashMap<NamedType, NamedType> collected = new HashMap<NamedType, NamedType>();
    // start with registered subtypes (which have precedence)
    if (_registeredSubtypes != null) {
        for (NamedType subtype : _registeredSubtypes) {
            // is it a subtype of root type?
            if (rawBase.isAssignableFrom(subtype.getType())) {
                // yes
                AnnotatedClass curr = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), config);
                _collectAndResolve(curr, subtype, config, ai, collected);
            }
        }
    }
    // then annotated types for property itself
    Collection<NamedType> st = ai.findSubtypes(property);
    if (st != null) {
        for (NamedType nt : st) {
            AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(nt.getType(), config);
            _collectAndResolve(ac, nt, config, ai, collected);
        }
    }
    NamedType rootType = new NamedType(rawBase, null);
    AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(rawBase, config);
    // and finally subtypes via annotations from base type (recursively)
    _collectAndResolve(ac, rootType, config, ai, collected);
    return new ArrayList<NamedType>(collected.values());
}
Also used : NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector)

Example 14 with AnnotationIntrospector

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

the class StdSubtypeResolver method collectAndResolveSubtypesByClass.

@Override
public Collection<NamedType> collectAndResolveSubtypesByClass(MapperConfig<?> config, AnnotatedClass type) {
    final AnnotationIntrospector ai = config.getAnnotationIntrospector();
    HashMap<NamedType, NamedType> subtypes = new HashMap<NamedType, NamedType>();
    // then consider registered subtypes (which have precedence over annotations)
    if (_registeredSubtypes != null) {
        Class<?> rawBase = type.getRawType();
        for (NamedType subtype : _registeredSubtypes) {
            // is it a subtype of root type?
            if (rawBase.isAssignableFrom(subtype.getType())) {
                // yes
                AnnotatedClass curr = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), config);
                _collectAndResolve(curr, subtype, config, ai, subtypes);
            }
        }
    }
    // and then check subtypes via annotations from base type (recursively)
    NamedType rootType = new NamedType(type.getRawType(), null);
    _collectAndResolve(type, rootType, config, ai, subtypes);
    return new ArrayList<NamedType>(subtypes.values());
}
Also used : NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector)

Aggregations

AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)14 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)4 JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)3 JaxbAnnotationIntrospector (com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JsonFormat (com.fasterxml.jackson.annotation.JsonFormat)1 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 PropertyName (com.fasterxml.jackson.databind.PropertyName)1 JsonPOJOBuilder (com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder)1 Annotated (com.fasterxml.jackson.databind.introspect.Annotated)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 AnnotationIntrospectorPair (com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair)1 Method (java.lang.reflect.Method)1