Java Code Examples for com.fasterxml.jackson.databind.cfg.MapperConfig#getAnnotationIntrospector()

The following examples show how to use com.fasterxml.jackson.databind.cfg.MapperConfig#getAnnotationIntrospector() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StdSubtypeResolver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 = AnnotatedClassResolver.resolveWithoutSuperTypes(config,
                        subtype.getType());
                _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());
}
 
Example 2
Source File: ConcreteBeanPropertyBase.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: ConcreteBeanPropertyBase.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public JsonInclude.Value findPropertyInclusion(MapperConfig<?> config, Class<?> baseType)
{
    AnnotationIntrospector intr = config.getAnnotationIntrospector();
    AnnotatedMember member = getMember();
    if (member == null) {
        JsonInclude.Value def = config.getDefaultPropertyInclusion(baseType);
        return def;
    }
    JsonInclude.Value v0 = config.getDefaultInclusion(baseType, member.getRawType());
    if (intr == null) {
        return v0;
    }
    JsonInclude.Value v = intr.findPropertyInclusion(member);
    if (v0 == null) {
        return v;
    }
    return v0.withOverrides(v);
}
 
Example 4
Source File: ConcreteBeanPropertyBase.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public List<PropertyName> findAliases(MapperConfig<?> config)
{
    List<PropertyName> aliases = _aliases;
    if (aliases == null) {
        AnnotationIntrospector intr = config.getAnnotationIntrospector();
        if (intr != null) {
            aliases = intr.findPropertyAliases(getMember());
        }
        if (aliases == null) {
            aliases = Collections.emptyList();
        }
        _aliases = aliases;
    }
    return aliases;
}
 
Example 5
Source File: RootNameLookup.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public PropertyName findRootName(Class<?> rootType, MapperConfig<?> config)
{
    ClassKey key = new ClassKey(rootType);
    PropertyName name = _rootNames.get(key); 
    if (name != null) {
        return name;
    }
    BeanDescription beanDesc = config.introspectClassAnnotations(rootType);
    AnnotationIntrospector intr = config.getAnnotationIntrospector();
    AnnotatedClass ac = beanDesc.getClassInfo();
    name = intr.findRootName(ac);
    // No answer so far? Let's just default to using simple class name
    if (name == null || !name.hasSimpleName()) {
        // Should we strip out enclosing class tho? For now, nope:
        name = PropertyName.construct(rootType.getSimpleName());
    }
    _rootNames.put(key, name);
    return name;
}
 
Example 6
Source File: BeanProperty.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JsonFormat.Value findPropertyFormat(MapperConfig<?> config, Class<?> baseType) {
    JsonFormat.Value v0 = config.getDefaultPropertyFormat(baseType);
    AnnotationIntrospector intr = config.getAnnotationIntrospector();
    if ((intr == null) || (_member == null)) {
        return v0;
    }
    JsonFormat.Value v = intr.findFormat(_member);
    if (v == null) {
        return v0;
    }
    return v0.withOverrides(v);
}
 
Example 7
Source File: BeanProperty.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JsonInclude.Value findPropertyInclusion(MapperConfig<?> config, Class<?> baseType)
{
    JsonInclude.Value v0 = config.getDefaultInclusion(baseType, _type.getRawClass());
    AnnotationIntrospector intr = config.getAnnotationIntrospector();
    if ((intr == null) || (_member == null)) {
        return v0;
    }
    JsonInclude.Value v = intr.findPropertyInclusion(_member);
    if (v == null) {
        return v0;
    }
    return v0.withOverrides(v);
}
 
Example 8
Source File: StdSubtypeResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Collection<NamedType> collectAndResolveSubtypesByTypeId(MapperConfig<?> config, 
        AnnotatedMember property, JavaType baseType)
{
    final AnnotationIntrospector ai = config.getAnnotationIntrospector();
    Class<?> rawBase = baseType.getRawClass();

    // Need to keep track of classes that have been handled already 
    Set<Class<?>> typesHandled = new HashSet<Class<?>>();
    Map<String,NamedType> byName = new LinkedHashMap<String,NamedType>();

    // start with lowest-precedence, which is from type hierarchy
    NamedType rootType = new NamedType(rawBase, null);
    AnnotatedClass ac = AnnotatedClassResolver.resolveWithoutSuperTypes(config,
            rawBase);
    _collectAndResolveByTypeId(ac, rootType, config, typesHandled, byName);
    
    // then with definitions from property
    if (property != null) {
        Collection<NamedType> st = ai.findSubtypes(property);
        if (st != null) {
            for (NamedType nt : st) {
                ac = AnnotatedClassResolver.resolveWithoutSuperTypes(config, nt.getType());
                _collectAndResolveByTypeId(ac, nt, config, typesHandled, byName);
            }            
        }
    }
    // and finally explicit type registrations (highest precedence)
    if (_registeredSubtypes != null) {
        for (NamedType subtype : _registeredSubtypes) {
            // is it a subtype of root type?
            if (rawBase.isAssignableFrom(subtype.getType())) { // yes
                AnnotatedClass curr = AnnotatedClassResolver.resolveWithoutSuperTypes(config,
                        subtype.getType());
                _collectAndResolveByTypeId(curr, subtype, config, typesHandled, byName);
            }
        }
    }
    return _combineNamedAndUnnamed(rawBase, typesHandled, byName);
}
 
Example 9
Source File: BasicClassIntrospector.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> config,
        JavaType type, MixInResolver r, boolean forSerialization)
{
    AnnotatedClass ac = _resolveAnnotatedClass(config, type, r);
    AnnotationIntrospector ai = config.isAnnotationProcessingEnabled() ? config.getAnnotationIntrospector() : null;
    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);
}
 
Example 10
Source File: AnnotatedClassResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
AnnotatedClassResolver(MapperConfig<?> config, JavaType type, MixInResolver r) {
    _config = config;
    _type = type;
    _class = type.getRawClass();
    _mixInResolver = r;
    _bindings = type.getBindings();
    _intr = config.isAnnotationProcessingEnabled()
            ? config.getAnnotationIntrospector() : null;
    _primaryMixin = _config.findMixInClassFor(_class);
}
 
Example 11
Source File: AnnotatedClassResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
AnnotatedClassResolver(MapperConfig<?> config, Class<?> cls, MixInResolver r) {
    _config = config;
    _type = null;
    _class = cls;
    _mixInResolver = r;
    _bindings = TypeBindings.emptyBindings();
    if (config == null) {
        _intr = null;
        _primaryMixin = null;
    } else {
        _intr = config.isAnnotationProcessingEnabled()
                ? config.getAnnotationIntrospector() : null;
        _primaryMixin = _config.findMixInClassFor(_class);
    }
}
 
Example 12
Source File: SimpleBeanPropertyDefinition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 2.2
 */
public static SimpleBeanPropertyDefinition construct(MapperConfig<?> config,
		AnnotatedMember member)
{
    return new SimpleBeanPropertyDefinition(config.getAnnotationIntrospector(),
            member, PropertyName.construct(member.getName()), null, EMPTY_INCLUDE);
}
 
Example 13
Source File: SimpleBeanPropertyDefinition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method called to create instance for virtual properties.
 *
 * @since 2.5
 */
public static SimpleBeanPropertyDefinition construct(MapperConfig<?> config,
        AnnotatedMember member, PropertyName name, PropertyMetadata metadata,
        JsonInclude.Include inclusion)
{
    JsonInclude.Value inclValue
         = ((inclusion == null) || (inclusion == JsonInclude.Include.USE_DEFAULTS)) 
         ? EMPTY_INCLUDE : JsonInclude.Value.construct(inclusion, null);
    return new SimpleBeanPropertyDefinition(config.getAnnotationIntrospector(),
            member, name, metadata, inclValue);
}
 
Example 14
Source File: SimpleBeanPropertyDefinition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 2.7
 */
public static SimpleBeanPropertyDefinition construct(MapperConfig<?> config,
        AnnotatedMember member, PropertyName name, PropertyMetadata metadata,
        JsonInclude.Value inclusion) {
      return new SimpleBeanPropertyDefinition(config.getAnnotationIntrospector(),
              member, name, metadata, inclusion);
}