Search in sources :

Example 21 with TypeDeserializer

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

the class MapEntryDeserializer method createContextual.

/*
    /**********************************************************
    /* Validation, post-processing (ResolvableDeserializer)
    /**********************************************************
     */
/**
     * 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);
}
Also used : TypeDeserializer(com.fasterxml.jackson.databind.jsontype.TypeDeserializer)

Example 22 with TypeDeserializer

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

the class ObjectArrayDeserializer method createContextual.

@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);
}
Also used : NullValueProvider(com.fasterxml.jackson.databind.deser.NullValueProvider) TypeDeserializer(com.fasterxml.jackson.databind.jsontype.TypeDeserializer)

Example 23 with TypeDeserializer

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

the class ReferenceTypeDeserializer method createContextual.

@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);
}
Also used : TypeDeserializer(com.fasterxml.jackson.databind.jsontype.TypeDeserializer)

Example 24 with TypeDeserializer

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

the class BasicDeserializerFactory method resolveMemberAndTypeAnnotations.

/**
     * Helper method used to resolve additional type-related annotation information
     * like type overrides, or handler (serializer, deserializer) overrides,
     * so that from declared field, property or constructor parameter type
     * is used as the base and modified based on annotations, if any.
     * 
     * @since 2.8 Combines functionality of <code>modifyTypeByAnnotation</code>
     *     and <code>resolveType</code>
     */
protected JavaType resolveMemberAndTypeAnnotations(DeserializationContext ctxt, AnnotatedMember member, JavaType type) throws JsonMappingException {
    AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
    if (intr == null) {
        return type;
    }
    if (type.isMapLikeType()) {
        JavaType keyType = type.getKeyType();
        if (keyType != null) {
            Object kdDef = intr.findKeyDeserializer(member);
            KeyDeserializer kd = ctxt.keyDeserializerInstance(member, kdDef);
            if (kd != null) {
                type = ((MapLikeType) type).withKeyValueHandler(kd);
                // just in case it's used below
                keyType = type.getKeyType();
            }
        }
    }
    if (type.hasContentType()) {
        // that is, is either container- or reference-type
        Object cdDef = intr.findContentDeserializer(member);
        JsonDeserializer<?> cd = ctxt.deserializerInstance(member, cdDef);
        if (cd != null) {
            type = type.withContentValueHandler(cd);
        }
        TypeDeserializer contentTypeDeser = findPropertyContentTypeDeserializer(ctxt.getConfig(), type, (AnnotatedMember) member);
        if (contentTypeDeser != null) {
            type = type.withContentTypeHandler(contentTypeDeser);
        }
    }
    TypeDeserializer valueTypeDeser = findPropertyTypeDeserializer(ctxt.getConfig(), type, (AnnotatedMember) member);
    if (valueTypeDeser != null) {
        type = type.withTypeHandler(valueTypeDeser);
    }
    // Second part: find actual type-override annotations on member, if any
    // 18-Jun-2016, tatu: Should we re-do checks for annotations on refined
    //   subtypes as well? Code pre-2.8 did not do this, but if we get bug
    //   reports may need to consider
    type = intr.refineDeserializationType(ctxt.getConfig(), member, type);
    return type;
}
Also used : TypeDeserializer(com.fasterxml.jackson.databind.jsontype.TypeDeserializer)

Example 25 with TypeDeserializer

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

the class BasicDeserializerFactory method createCollectionDeserializer.

/*
    /**********************************************************
    /* JsonDeserializerFactory impl: Collection(-like) deserializers
    /**********************************************************
     */
@Override
public JsonDeserializer<?> createCollectionDeserializer(DeserializationContext ctxt, CollectionType type, BeanDescription beanDesc) throws JsonMappingException {
    JavaType contentType = type.getContentType();
    // Very first thing: is deserializer hard-coded for elements?
    JsonDeserializer<Object> contentDeser = contentType.getValueHandler();
    final DeserializationConfig config = ctxt.getConfig();
    // Then optional type info: if type has been resolved, we may already know type deserializer:
    TypeDeserializer contentTypeDeser = contentType.getTypeHandler();
    // but if not, may still be possible to find:
    if (contentTypeDeser == null) {
        contentTypeDeser = findTypeDeserializer(config, contentType);
    }
    // 23-Nov-2010, tatu: Custom deserializer?
    JsonDeserializer<?> deser = _findCustomCollectionDeserializer(type, config, beanDesc, contentTypeDeser, contentDeser);
    if (deser == null) {
        Class<?> collectionClass = type.getRawClass();
        if (contentDeser == null) {
            // One special type: EnumSet:
            if (EnumSet.class.isAssignableFrom(collectionClass)) {
                deser = new EnumSetDeserializer(contentType, null);
            }
        }
    }
    /* One twist: if we are being asked to instantiate an interface or
         * abstract Collection, we need to either find something that implements
         * the thing, or give up.
         *
         * Note that we do NOT try to guess based on secondary interfaces
         * here; that would probably not work correctly since casts would
         * fail later on (as the primary type is not the interface we'd
         * be implementing)
         */
    if (deser == null) {
        if (type.isInterface() || type.isAbstract()) {
            CollectionType implType = _mapAbstractCollectionType(type, config);
            if (implType == null) {
                // [databind#292]: Actually, may be fine, but only if polymorphich deser enabled
                if (type.getTypeHandler() == null) {
                    throw new IllegalArgumentException("Can not find a deserializer for non-concrete Collection type " + type);
                }
                deser = AbstractDeserializer.constructForNonPOJO(beanDesc);
            } else {
                type = implType;
                // But if so, also need to re-check creators...
                beanDesc = config.introspectForCreation(type);
            }
        }
        if (deser == null) {
            ValueInstantiator inst = findValueInstantiator(ctxt, beanDesc);
            if (!inst.canCreateUsingDefault()) {
                // [databind#161]: No default constructor for ArrayBlockingQueue...
                if (type.getRawClass() == ArrayBlockingQueue.class) {
                    return new ArrayBlockingQueueDeserializer(type, contentDeser, contentTypeDeser, inst);
                }
            }
            // Can use more optimal deserializer if content type is String, so:
            if (contentType.getRawClass() == String.class) {
                // no value type deserializer because Strings are one of natural/native types:
                deser = new StringCollectionDeserializer(type, contentDeser, inst);
            } else {
                deser = new CollectionDeserializer(type, contentDeser, contentTypeDeser, inst);
            }
        }
    }
    // allow post-processing it too
    if (_factoryConfig.hasDeserializerModifiers()) {
        for (BeanDeserializerModifier mod : _factoryConfig.deserializerModifiers()) {
            deser = mod.modifyCollectionDeserializer(config, type, beanDesc, deser);
        }
    }
    return deser;
}
Also used : TypeDeserializer(com.fasterxml.jackson.databind.jsontype.TypeDeserializer)

Aggregations

TypeDeserializer (com.fasterxml.jackson.databind.jsontype.TypeDeserializer)30 IOException (java.io.IOException)9 JsonIgnoreProperties (com.fasterxml.jackson.annotation.JsonIgnoreProperties)2 ObjectBuffer (com.fasterxml.jackson.databind.util.ObjectBuffer)2 NullValueProvider (com.fasterxml.jackson.databind.deser.NullValueProvider)1 PropertyBasedCreator (com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator)1 PropertyValueBuffer (com.fasterxml.jackson.databind.deser.impl.PropertyValueBuffer)1 Referring (com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring)1 TypeWrappedDeserializer (com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer)1 AnnotatedMember (com.fasterxml.jackson.databind.introspect.AnnotatedMember)1