Java Code Examples for com.fasterxml.jackson.databind.cfg.MapperConfig

The following examples show how to use com.fasterxml.jackson.databind.cfg.MapperConfig. These examples are extracted from open source projects. 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
@Override
public PropertyName findNameForDeserialization(MapperConfig<?> config, Annotated a)
{
    // 16-Sep-2016, tatu: Prior to 2.9 logic her more complicated, on assumption
    //    that visibility rules may require return of "" if method/fied visible;
    //    however, that is not required and causes issues so... now simpler:
    if (a instanceof AnnotatedMethod) {
        AnnotatedMethod am = (AnnotatedMethod) a;
        if (!isVisible(am)) {
            return null;
        }
        Class<?> rawType = am.getRawParameterType(0);
        return findJaxbPropertyName(am, rawType, BeanUtil.okNameForMutator(am, "set"));
    }
    if (a instanceof AnnotatedField) {
        AnnotatedField af = (AnnotatedField) a;
        return isVisible(af)
            ? findJaxbPropertyName(af, af.getRawType(), null)
            : null;
    }
    return null;
}
 
Example 2
@Override
public Boolean hasRequiredMarker(MapperConfig<?> config, AnnotatedMember m) {
    // 17-Oct-2017, tatu: [modules-base#32]
    //   Before 2.9.3, was handling `true` correctly,
    //   but otherwise used confusing logic (probably in attempt to try to avoid
    //   reporting not-required for default value case
    XmlAttribute attr = m.getAnnotation(XmlAttribute.class);
    if (attr != null) {
        return attr.required();
    }
    XmlElement elem = m.getAnnotation(XmlElement.class);
    if (elem != null) {
        return elem.required();
    }
    return null;
}
 
Example 3
@Override
public PropertyName findNameForDeserialization(MapperConfig<?> config, Annotated a)
{
    /* 14-Apr-2014, tatu: Important -- we should NOT introspect name here,
     *   since we are not using annotations; instead it needs to be done
     *   in {@link #findParameterSourceName(AnnotatedParameter)}.
     */
    /*
    PropertyName name = super.findNameForDeserialization(a);
    if (name == null) {
        if (a instanceof AnnotatedParameter) {
            String rawName _paranamer.findParameterName((AnnotatedParameter) a);
            if (rawName != null) {
                return new PropertyName(rawName);
            }
        }
    }
    */
    return null;
}
 
Example 4
Source Project: lams   Source File: StdSubtypeResolver.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public Collection<NamedType> collectAndResolveSubtypesByTypeId(MapperConfig<?> config,
        AnnotatedClass baseType)
{
    final Class<?> rawBase = baseType.getRawType();
    Set<Class<?>> typesHandled = new HashSet<Class<?>>();
    Map<String,NamedType> byName = new LinkedHashMap<String,NamedType>();

    NamedType rootType = new NamedType(rawBase, null);
    _collectAndResolveByTypeId(baseType, rootType, config, typesHandled, byName);
    
    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 5
@Override
public PropertyName findNameForDeserialization(MapperConfig<?> config, Annotated a)
{
    /* 14-Apr-2014, tatu: Important -- we should NOT introspect name here,
     *   since we are not using annotations; instead it needs to be done
     *   in {@link #findParameterSourceName(AnnotatedParameter)}.
     */
    /*
    PropertyName name = super.findNameForDeserialization(a);
    if (name == null) {
        if (a instanceof AnnotatedParameter) {
            String rawName _paranamer.findParameterName((AnnotatedParameter) a);
            if (rawName != null) {
                return new PropertyName(rawName);
            }
        }
    }
    */
    return null;
}
 
Example 6
@Override
public PropertyName findNameForSerialization(MapperConfig<?> config, Annotated a)
{
    // 16-Sep-2016, tatu: Prior to 2.9 logic her more complicated, on assumption
    //    that visibility rules may require return of "" if method/fied visible;
    //    however, that is not required and causes issues so... now simpler:
    if (a instanceof AnnotatedMethod) {
        AnnotatedMethod am = (AnnotatedMethod) a;
        return isVisible(am)
            ? findJaxbPropertyName(am, am.getRawType(), BeanUtil.okNameForGetter(am))
            : null;
    }
    if (a instanceof AnnotatedField) {
        AnnotatedField af = (AnnotatedField) a;
        return isVisible(af)
            ? findJaxbPropertyName(af, af.getRawType(), null)
            : null;
    }
    return null;
}
 
Example 7
protected BeanPropertyWriter _constructVirtualProperty(JsonAppend.Attr attr,
        MapperConfig<?> config, AnnotatedClass ac, JavaType type)
{
    PropertyMetadata metadata = attr.required() ?
                PropertyMetadata.STD_REQUIRED : PropertyMetadata.STD_OPTIONAL;
    // could add Index, Description in future, if those matter
    String attrName = attr.value();

    // allow explicit renaming; if none, default to attribute name
    PropertyName propName = _propertyName(attr.propName(), attr.propNamespace());
    if (!propName.hasSimpleName()) {
        propName = PropertyName.construct(attrName);
    }
    // now, then, we need a placeholder for member (no real Field/Method):
    AnnotatedMember member = new VirtualAnnotatedMember(ac, ac.getRawType(),
            attrName, type);
    // and with that and property definition
    SimpleBeanPropertyDefinition propDef = SimpleBeanPropertyDefinition.construct(config,
            member, propName, metadata, attr.include());
    // can construct the property writer
    return AttributePropertyWriter.construct(attrName, propDef,
            ac.getAnnotations(), type);
}
 
Example 8
@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 9
protected Converter<Object,Object> _converter(MapperConfig<?> config,
        XmlAdapter<?,?> adapter, boolean forSerialization)
{
    TypeFactory tf = config.getTypeFactory();
    JavaType adapterType = tf.constructType(adapter.getClass());
    JavaType[] pt = tf.findTypeParameters(adapterType, XmlAdapter.class);
    // Order of type parameters for Converter is reverse between serializer, deserializer,
    // whereas JAXB just uses single ordering
    if (forSerialization) {
        return new AdapterConverter(adapter, pt[1], pt[0], forSerialization);
    }
    return new AdapterConverter(adapter, pt[0], pt[1], forSerialization);
}
 
Example 10
Source Project: spring-analysis-note   Source File: SpringHandlerInstantiator.java    License: MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public ValueInstantiator valueInstantiatorInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (ValueInstantiator) this.beanFactory.createBean(implClass);
}
 
Example 11
Source Project: spring-analysis-note   Source File: SpringHandlerInstantiator.java    License: MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public ObjectIdGenerator<?> objectIdGeneratorInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (ObjectIdGenerator<?>) this.beanFactory.createBean(implClass);
}
 
Example 12
Source Project: spring-analysis-note   Source File: SpringHandlerInstantiator.java    License: MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public PropertyNamingStrategy namingStrategyInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (PropertyNamingStrategy) this.beanFactory.createBean(implClass);
}
 
Example 13
Source Project: spring-analysis-note   Source File: SpringHandlerInstantiator.java    License: MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public Converter<?, ?> converterInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (Converter<?, ?>) this.beanFactory.createBean(implClass);
}
 
Example 14
Source Project: java-technology-stack   Source File: SpringHandlerInstantiator.java    License: MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public ValueInstantiator valueInstantiatorInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (ValueInstantiator) this.beanFactory.createBean(implClass);
}
 
Example 15
Source Project: java-technology-stack   Source File: SpringHandlerInstantiator.java    License: MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public ObjectIdResolver resolverIdGeneratorInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (ObjectIdResolver) this.beanFactory.createBean(implClass);
}
 
Example 16
Source Project: java-technology-stack   Source File: SpringHandlerInstantiator.java    License: MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public Converter<?, ?> converterInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (Converter<?, ?>) this.beanFactory.createBean(implClass);
}
 
Example 17
Source Project: lams   Source File: AnnotatedClassResolver.java    License: 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 18
@Override
public String[] findEnumValues(MapperConfig<?> config, 
        Class<?> enumType, Enum<?>[] enumValues, String[] names) {
    HashMap<String,String> expl = null;
    for (Field f : enumType.getDeclaredFields()) {
        if (!f.isEnumConstant()) {
            continue;
        }
        XmlEnumValue enumValue = f.getAnnotation(XmlEnumValue.class);
        if (enumValue == null) {
            continue;
        }
        String n = enumValue.value();
        if (n.isEmpty()) {
            continue;
        }
        if (expl == null) {
            expl = new HashMap<String,String>();
        }
        expl.put(f.getName(), n);
    }
    // and then stitch them together if and as necessary
    if (expl != null) {
        for (int i = 0, end = enumValues.length; i < end; ++i) {
            String defName = enumValues[i].name();
            String explValue = expl.get(defName);
            if (explValue != null) {
                names[i] = explValue;
            }
        }
    }
    return names;
}
 
Example 19
Source Project: soundwave   Source File: EsPropertyNamingStrategy.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String nameForSetterMethod(MapperConfig<?> config, AnnotatedMethod method,
                                  String defaultName) {
  if (method.getDeclaringClass() == this.effectiveType) {
    return fieldToJsonMapping
        .getOrDefault(defaultName, super.nameForSetterMethod(config, method, defaultName));
  } else {
    return super.nameForSetterMethod(config, method, defaultName);
  }
}
 
Example 20
Source Project: lams   Source File: BeanProperty.java    License: 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 21
private boolean adapterTypeMatches(MapperConfig<?> config, XmlAdapter<?,?> adapter,
        Class<?> targetType)
{
    JavaType adapterType = config.constructType(adapter.getClass());
    JavaType[] params = config.getTypeFactory().findTypeParameters(adapterType, XmlAdapter.class);
    // should not happen, except if our type resolution has a flaw, but:
    Class<?> boundType = (params == null || params.length < 2) ? Object.class
            : params[1].getRawClass();
    return boundType.isAssignableFrom(targetType);
}
 
Example 22
@Override
public Object findSerializationConverter(MapperConfig<?> config, Annotated a)
{
    Class<?> serType = _rawSerializationType(a);
    // Can apply to both container and regular type; no difference yet here
    XmlAdapter<?,?> adapter = findAdapter(config, a, true, serType);
    if (adapter != null) {
        return _converter(config, adapter, true);
    }
    return null;
}
 
Example 23
Source Project: lams   Source File: StdSubtypeResolver.java    License: 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 24
@Override
public String findImplicitPropertyName(MapperConfig<?> config, AnnotatedMember m) {
    XmlValue valueInfo = m.getAnnotation(XmlValue.class);
    if (valueInfo != null) {
        return _xmlValueName;
    }
    return null;
}
 
Example 25
/**
 * @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);
}
 
Example 26
Source Project: lams   Source File: BasicBeanDescription.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Factory method to use for constructing an instance to use for purposes
 * other than building serializers or deserializers; will only have information
 * on class, not on properties.
 */
public static BasicBeanDescription forOtherUse(MapperConfig<?> config,
        JavaType type, AnnotatedClass ac)
{
    return new BasicBeanDescription(config, type,
            ac, Collections.<BeanPropertyDefinition>emptyList());
}
 
Example 27
@Override
public Object findDeserializationConverter(MapperConfig<?> config, Annotated a)
{
    // One limitation: for structured types this is done later on
    Class<?> deserType = _rawDeserializationType(a);
    XmlAdapter<?,?> adapter = findAdapter(config, a, true, deserType);
    if (adapter != null) {
        return _converter(config, adapter, false);
    }
    return null;
}
 
Example 28
@Override
public TypeResolverBuilder<?> findTypeResolver(MapperConfig<?> config,
        AnnotatedClass ac, JavaType baseType)
{
    TypeResolverBuilder<?> b = _primary.findTypeResolver(config, ac, baseType);
    if (b == null) {
        b = _secondary.findTypeResolver(config, ac, baseType);
    }
    return b;
}
 
Example 29
Source Project: lams   Source File: BasicClassIntrospector.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected BasicBeanDescription _findStdJdkCollectionDesc(MapperConfig<?> cfg, JavaType type)
{
    if (_isStdJDKCollection(type)) {
        return BasicBeanDescription.forOtherUse(cfg, type,
                _resolveAnnotatedClass(cfg, type, cfg));
    }
    return null;
}
 
Example 30
@Override // since 2.9
public JacksonInject.Value findInjectableValue(MapperConfig<?> config, AnnotatedMember m) {
    Object id = _findGuiceInjectId(m);
    if (id == null) {
        return null;
    }
    return JacksonInject.Value.forId(id);
}