Java Code Examples for com.fasterxml.jackson.databind.jsontype.TypeDeserializer#forProperty()

The following examples show how to use com.fasterxml.jackson.databind.jsontype.TypeDeserializer#forProperty() . 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: ObjectArrayDeserializer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
        BeanProperty property) throws JsonMappingException
{
    JsonDeserializer<?> valueDeser = _elementDeserializer;
    Boolean unwrapSingle = findFormatFeature(ctxt, property, _containerType.getRawClass(),
            JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
    // May have a content converter
    valueDeser = findConvertingContentDeserializer(ctxt, property, valueDeser);
    final JavaType vt = _containerType.getContentType();
    if (valueDeser == null) {
        valueDeser = ctxt.findContextualValueDeserializer(vt, property);
    } else { // if directly assigned, probably not yet contextual, so:
        valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
    }
    TypeDeserializer elemTypeDeser = _elementTypeDeserializer;
    if (elemTypeDeser != null) {
        elemTypeDeser = elemTypeDeser.forProperty(property);
    }
    NullValueProvider nuller = findContentNullProvider(ctxt, property, valueDeser);
    return withResolved(elemTypeDeser, valueDeser, nuller, unwrapSingle);
}
 
Example 2
Source File: OptionDeserializer.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
    JsonDeserializer<?> deser = valueDeserializer;
    TypeDeserializer typeDeser = valueTypeDeserializer;
    JavaType refType = valueType;

    if (deser == null) {
        deser = ctxt.findContextualValueDeserializer(refType, property);
    } else { // otherwise directly assigned, probably not contextual yet:
        deser = ctxt.handleSecondaryContextualization(deser, property, refType);
    }
    if (typeDeser != null) {
        typeDeser = typeDeser.forProperty(property);
    }
    return withResolved(refType, typeDeser, deser);
}
 
Example 3
Source File: LazyDeserializer.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
    JsonDeserializer<?> deser = valueDeserializer;
    TypeDeserializer typeDeser = valueTypeDeserializer;
    JavaType refType = valueType;

    if (deser == null) {
        deser = ctxt.findContextualValueDeserializer(refType, property);
    } else { // otherwise directly assigned, probably not contextual yet:
        deser = ctxt.handleSecondaryContextualization(deser, property, refType);
    }
    if (typeDeser != null) {
        typeDeser = typeDeser.forProperty(property);
    }
    return new LazyDeserializer(this, typeDeser, deser);
}
 
Example 4
Source File: BaseCollectionDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property)
        throws JsonMappingException {
    JsonDeserializer<?> deser = _valueDeserializer;
    TypeDeserializer typeDeser = _typeDeserializerForValue;
    if (deser == null) {
        deser = ctxt.findContextualValueDeserializer(_elementType, property);
    }
    if (typeDeser != null) {
        typeDeser = typeDeser.forProperty(property);
    }
    if (deser == _valueDeserializer && typeDeser == _typeDeserializerForValue) {
        return this;
    }
    return withResolved(typeDeser, deser);
}
 
Example 5
Source File: PCollectionsMapDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
/**
 * Method called to finalize setup of this deserializer,
 * after deserializer itself has been registered. This
 * is needed to handle recursive and transitive dependencies.
 */
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
        BeanProperty property) throws JsonMappingException
{
    KeyDeserializer keyDeser = _keyDeserializer;
    JsonDeserializer<?> deser = _valueDeserializer;
    TypeDeserializer typeDeser = _typeDeserializerForValue;
    // Do we need any contextualization?
    if ((keyDeser != null) && (deser != null) && (typeDeser == null)) { // nope
        return this;
    }
    if (keyDeser == null) {
        keyDeser = ctxt.findKeyDeserializer(_mapType.getKeyType(), property);
    }
    if (deser == null) {
        deser = ctxt.findContextualValueDeserializer(_mapType.getContentType(), property);
    }
    if (typeDeser != null) {
        typeDeser = typeDeser.forProperty(property);
    }
    return withResolved(keyDeser, typeDeser, deser);
}
 
Example 6
Source File: PCollectionsCollectionDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
/**
 * Method called to finalize setup of this deserializer,
 * after deserializer itself has been registered. This
 * is needed to handle recursive and transitive dependencies.
 */
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
        BeanProperty property) throws JsonMappingException
{
    JsonDeserializer<?> deser = _valueDeserializer;
    TypeDeserializer typeDeser = _typeDeserializerForValue;
    if (deser == null) {
        deser = ctxt.findContextualValueDeserializer(_containerType.getContentType(), property);
    }
    if (typeDeser != null) {
        typeDeser = typeDeser.forProperty(property);
    }
    if (deser == _valueDeserializer && typeDeser == _typeDeserializerForValue) {
        return this;
    }
    return withResolved(typeDeser, deser);
}
 
Example 7
Source File: GuavaMultimapDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
/**
 * We need to use this method to properly handle possible contextual variants of key and value
 * deserializers, as well as type deserializers.
 */
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
        BeanProperty property) throws JsonMappingException
{
    KeyDeserializer kd = _keyDeserializer;
    if (kd == null) {
        kd = ctxt.findKeyDeserializer(_containerType.getKeyType(), property);
    }
    JsonDeserializer<?> valueDeser = _valueDeserializer;
    final JavaType vt = _containerType.getContentType();
    if (valueDeser == null) {
        valueDeser = ctxt.findContextualValueDeserializer(vt, property);
    } else { // if directly assigned, probably not yet contextual, so:
        valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
    }
    // Type deserializer is slightly different; must be passed, but needs to become contextual:
    TypeDeserializer vtd = _valueTypeDeserializer;
    if (vtd != null) {
        vtd = vtd.forProperty(property);
    }
    return _createContextual(_containerType, kd, vtd, valueDeser, creatorMethod,
            findContentNullProvider(ctxt, property, valueDeser));
}
 
Example 8
Source File: BaseRefCollectionDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property)
        throws JsonMappingException {
    JsonDeserializer<?> deser = _valueDeserializer;
    TypeDeserializer typeDeser = _typeDeserializerForValue;
    if (deser == null) {
        deser = ctxt.findContextualValueDeserializer(_elementType, property);
    }
    if (typeDeser != null) {
        typeDeser = typeDeser.forProperty(property);
    }
    if (deser == _valueDeserializer && typeDeser == _typeDeserializerForValue) {
        return this;
    }
    return withResolved(typeDeser, deser);
}
 
Example 9
Source File: RefValueHandler.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
@Override
public RefValueHandler createContextualValue(DeserializationContext ctxt, BeanProperty property)
        throws JsonMappingException {
    JsonDeserializer<?> deser;
    if (_valueDeserializer == null) {
        deser = ctxt.findContextualValueDeserializer(_valueType, property);
    } else {
        deser = _valueDeserializer;
    }
    TypeDeserializer typeDeser = _typeDeserializerForValue == null ?
            ctxt.findTypeDeserializer(_valueType) : _typeDeserializerForValue;
    if (typeDeser != null) {
        typeDeser = typeDeser.forProperty(property);
    }
    //noinspection ObjectEquality
    if (deser == _valueDeserializer && typeDeser == _typeDeserializerForValue) {
        return this;
    }
    return new RefValueHandler(_valueType, deser, typeDeser);
}
 
Example 10
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method for finding a deserializer for root-level value.
 */
@SuppressWarnings("unchecked")
public final JsonDeserializer<Object> findRootValueDeserializer(JavaType type)
    throws JsonMappingException
{
    JsonDeserializer<Object> deser = _cache.findValueDeserializer(this,
            _factory, type);
    if (deser == null) { // can this occur?
        return null;
    }
    deser = (JsonDeserializer<Object>) handleSecondaryContextualization(deser, null, type);
    TypeDeserializer typeDeser = _factory.findTypeDeserializer(_config, type);
    if (typeDeser != null) {
        // important: contextualize to indicate this is for root value
        typeDeser = typeDeser.forProperty(null);
        return new TypeWrappedDeserializer(typeDeser, deser);
    }
    return deser;
}
 
Example 11
Source File: BeanDeserializerBase.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
        AnnotatedWithParams delegateCreator) throws JsonMappingException {
    // Need to create a temporary property to allow contextual deserializers:
    BeanProperty.Std property = new BeanProperty.Std(TEMP_PROPERTY_NAME,
            delegateType, null, delegateCreator,
            PropertyMetadata.STD_OPTIONAL);

    TypeDeserializer td = delegateType.getTypeHandler();
    if (td == null) {
        td = ctxt.getConfig().findTypeDeserializer(delegateType);
    }
    JsonDeserializer<Object> dd = findDeserializer(ctxt, delegateType, property);
    if (td != null) {
        td = td.forProperty(property);
        return new TypeWrappedDeserializer(td, dd);
    }
    return dd;
}
 
Example 12
Source File: EnumMapDeserializer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method called to finalize setup of this deserializer,
 * when it is known for which property deserializer is needed for.
 */
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException
{
    // note: instead of finding key deserializer, with enums we actually
    // work with regular deserializers (less code duplication; but not
    // quite as clean as it ought to be)
    KeyDeserializer keyDeser = _keyDeserializer;
    if (keyDeser == null) {
        keyDeser = ctxt.findKeyDeserializer(_containerType.getKeyType(), property);
    }
    JsonDeserializer<?> valueDeser = _valueDeserializer;
    final JavaType vt = _containerType.getContentType();
    if (valueDeser == null) {
        valueDeser = ctxt.findContextualValueDeserializer(vt, property);
    } else { // if directly assigned, probably not yet contextual, so:
        valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
    }
    TypeDeserializer vtd = _valueTypeDeserializer;
    if (vtd != null) {
        vtd = vtd.forProperty(property);
    }
    return withResolved(keyDeser, valueDeser, vtd, findContentNullProvider(ctxt, property, valueDeser));
}
 
Example 13
Source File: ReferenceTypeDeserializer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property)
        throws JsonMappingException
{
    JsonDeserializer<?> deser = _valueDeserializer;
    if (deser == null) {
        deser = ctxt.findContextualValueDeserializer(_fullType.getReferencedType(), property);
    } else { // otherwise directly assigned, probably not contextual yet:
        deser = ctxt.handleSecondaryContextualization(deser, property, _fullType.getReferencedType());            
    }
    TypeDeserializer typeDeser = _valueTypeDeserializer;
    if (typeDeser != null) {
        typeDeser = typeDeser.forProperty(property);
    }
    // !!! 23-Oct-2016, tatu: TODO: full support for configurable ValueInstantiators?
    if ((deser == _valueDeserializer) && (typeDeser == _valueTypeDeserializer)) {
        return this;
    }
    return withResolved(typeDeser, deser);
}
 
Example 14
Source File: GuavaCollectionDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
/**
 * Method called to finalize setup of this deserializer,
 * after deserializer itself has been registered. This
 * is needed to handle recursive and transitive dependencies.
 */
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
        BeanProperty property) throws JsonMappingException
{
    Boolean unwrapSingle = findFormatFeature(ctxt, property, Collection.class,
            JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);

    JsonDeserializer<?> valueDeser = _valueDeserializer;
    TypeDeserializer valueTypeDeser = _valueTypeDeserializer;
    if (valueDeser == null) {
        valueDeser = ctxt.findContextualValueDeserializer(_containerType.getContentType(), property);
    }
    if (valueTypeDeser != null) {
        valueTypeDeser = valueTypeDeser.forProperty(property);
    }

    NullValueProvider nuller = findContentNullProvider(ctxt, property, valueDeser);

    if ( (unwrapSingle != _unwrapSingle)
            || (nuller != _nullProvider)
            || (valueDeser != _valueDeserializer)
            || (valueTypeDeser != _valueTypeDeserializer)) {
        return withResolved(valueDeser, valueTypeDeser, nuller, unwrapSingle);
    }
    return this;
}
 
Example 15
Source File: SettableBeanProperty.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected SettableBeanProperty(PropertyName propName, JavaType type, PropertyName wrapper,
        TypeDeserializer typeDeser, Annotations contextAnnotations,
        PropertyMetadata metadata)
{
    super(metadata);
    // 09-Jan-2009, tatu: Intern()ing makes sense since Jackson parsed
    //  field names are (usually) interned too, hence lookups will be faster.
    // 23-Oct-2009, tatu: should this be disabled wrt [JACKSON-180]?
    //   Probably need not, given that namespace of field/method names
    //   is not unbounded, unlike potential JSON names.
    if (propName == null) {
        _propName = PropertyName.NO_NAME;
    } else {
        _propName = propName.internSimpleName();
    }
    _type = type;
    _wrapperName = wrapper;
    _contextAnnotations = contextAnnotations;
    _viewMatcher = null;

    // 30-Jan-2012, tatu: Important: contextualize TypeDeserializer now...
    if (typeDeser != null) {
        typeDeser = typeDeser.forProperty(this);
    }
    _valueTypeDeserializer = typeDeser;
    _valueDeserializer = MISSING_VALUE_DESERIALIZER;
    _nullProvider = MISSING_VALUE_DESERIALIZER;
}
 
Example 16
Source File: MapEntryDeserializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method called to finalize setup of this deserializer,
 * when it is known for which property deserializer is needed for.
 */
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
        BeanProperty property) throws JsonMappingException
{
    KeyDeserializer kd = _keyDeserializer;
    if (kd == null) {
        kd = ctxt.findKeyDeserializer(_containerType.containedType(0), property);
    } else {
        if (kd instanceof ContextualKeyDeserializer) {
            kd = ((ContextualKeyDeserializer) kd).createContextual(ctxt, property);
        }
    }
    JsonDeserializer<?> vd = _valueDeserializer;
    vd = findConvertingContentDeserializer(ctxt, property, vd);
    JavaType contentType = _containerType.containedType(1);
    if (vd == null) {
        vd = ctxt.findContextualValueDeserializer(contentType, property);
    } else { // if directly assigned, probably not yet contextual, so:
        vd = ctxt.handleSecondaryContextualization(vd, property, contentType);
    }
    TypeDeserializer vtd = _valueTypeDeserializer;
    if (vtd != null) {
        vtd = vtd.forProperty(property);
    }
    return withResolved(kd, vtd, vd);
}
 
Example 17
Source File: IterableXDeserializer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
                                            BeanProperty property) throws JsonMappingException
{
    JsonDeserializer<?> deser = this.valueDeserializer;
    TypeDeserializer typeDeser = this.typeDeserializerForValue;
    if (deser == null) {
        deser = ctxt.findContextualValueDeserializer(type.getContentType(), property);
    }
    if (typeDeser != null) {
        typeDeser = typeDeser.forProperty(property);
    }

    return new IterableXDeserializer(elementType,itX,typeDeser, deser,type);
}
 
Example 18
Source File: ArrayDeserializer.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
    JsonDeserializer<?> elementDeser = elementDeserializer;
    TypeDeserializer elementTypeDeser = elementTypeDeserializer;

    if (elementDeser == null) {
        elementDeser = ctxt.findContextualValueDeserializer(elementType, property);
    } else {
        elementDeser = ctxt.handleSecondaryContextualization(elementDeser, property, elementType);
    }
    if (elementTypeDeser != null) {
        elementTypeDeser = elementTypeDeser.forProperty(property);
    }
    return createDeserializer(elementTypeDeser, elementDeser);
}
 
Example 19
Source File: GuavaMapDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 4 votes vote down vote up
/**
 * Method called to finalize setup of this deserializer,
 * after deserializer itself has been registered. This
 * is needed to handle recursive and transitive dependencies.
 */
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
        BeanProperty property) throws JsonMappingException
{
    KeyDeserializer keyDeser = _keyDeserializer;
    JsonDeserializer<?> valueDeser = _valueDeserializer;
    TypeDeserializer valueTypeDeser = _valueTypeDeserializer;

    // First: fetch and/or contextualize deserializers (key, value, value type)
    if (keyDeser == null) {
        keyDeser = ctxt.findKeyDeserializer(_containerType.getKeyType(), property);
    } else {
        if (keyDeser instanceof ContextualKeyDeserializer) {
            keyDeser = ((ContextualKeyDeserializer) keyDeser).createContextual(ctxt, property);
        }
    }
    final JavaType vt = _containerType.getContentType();
    if (valueDeser == null) {
        valueDeser = ctxt.findContextualValueDeserializer(vt, property);
    } else {
        valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
    }
    if (valueTypeDeser != null) {
        valueTypeDeser = valueTypeDeser.forProperty(property);
    }

    // Then other handlers

    NullValueProvider nuller = findContentNullProvider(ctxt, property, valueDeser);

    // !!! 08-Aug-2019, tatu: TODO: null skipping? Ignored properties?
    
    if ((_keyDeserializer == keyDeser) && (_valueDeserializer == valueDeser)
            && (_valueTypeDeserializer == valueTypeDeser)
            && (_nullProvider == nuller)
            ) {
        return this;
    }
    
    return withResolved(keyDeser, valueDeser, valueTypeDeser, nuller);
}
 
Example 20
Source File: MapDeserializer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Method called to finalize setup of this deserializer,
 * when it is known for which property deserializer is needed for.
 */
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
        BeanProperty property) throws JsonMappingException
{
    KeyDeserializer keyDeser = _keyDeserializer;
    if (keyDeser == null) {
        keyDeser = ctxt.findKeyDeserializer(_containerType.getKeyType(), property);
    } else {
        if (keyDeser instanceof ContextualKeyDeserializer) {
            keyDeser = ((ContextualKeyDeserializer) keyDeser).createContextual(ctxt, property);
        }
    }
    
    JsonDeserializer<?> valueDeser = _valueDeserializer;
    // [databind#125]: May have a content converter
    if (property != null) {
        valueDeser = findConvertingContentDeserializer(ctxt, property, valueDeser);
    }
    final JavaType vt = _containerType.getContentType();
    if (valueDeser == null) {
        valueDeser = ctxt.findContextualValueDeserializer(vt, property);
    } else { // if directly assigned, probably not yet contextual, so:
        valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
    }
    TypeDeserializer vtd = _valueTypeDeserializer;
    if (vtd != null) {
        vtd = vtd.forProperty(property);
    }
    Set<String> ignored = _ignorableProperties;
    AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
    if (_neitherNull(intr, property)) {
        AnnotatedMember member = property.getMember();
        if (member != null) {
            JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnorals(member);
            if (ignorals != null) {
                Set<String> ignoresToAdd = ignorals.findIgnoredForDeserialization();
                if (!ignoresToAdd.isEmpty()) {
                    ignored = (ignored == null) ? new HashSet<String>() : new HashSet<String>(ignored);
                    for (String str : ignoresToAdd) {
                        ignored.add(str);
                    }
                }
            }
        }
    }
    return withResolved(keyDeser, vtd, valueDeser,
            findContentNullProvider(ctxt, property, valueDeser), ignored);
}