com.fasterxml.jackson.databind.jsontype.TypeDeserializer Java Examples

The following examples show how to use com.fasterxml.jackson.databind.jsontype.TypeDeserializer. 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: VavrDeserializers.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
@Override
public JsonDeserializer<?> findMapLikeDeserializer(MapLikeType type,
                                                   DeserializationConfig config, BeanDescription beanDesc,
                                                   KeyDeserializer keyDeserializer,
                                                   TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
        throws JsonMappingException
{
    Class<?> raw = type.getRawClass();
    if (Map.class.isAssignableFrom(raw)) {
        return new MapDeserializer(type, keyDeserializer, elementTypeDeserializer, elementDeserializer);
    }
    if (Multimap.class.isAssignableFrom(raw)) {
        return new MultimapDeserializer(type, keyDeserializer, elementTypeDeserializer, elementDeserializer);
    }
    return super.findMapLikeDeserializer(type, config, beanDesc, keyDeserializer, elementTypeDeserializer, elementDeserializer);
}
 
Example #2
Source File: BasicDeserializerFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method called to create a type information deserializer for values of
 * given non-container property, if one is needed.
 * If not needed (no polymorphic handling configured for property), should return null.
 *<p>
 * Note that this method is only called for non-container bean properties,
 * and not for values in container types or root values (or container properties)
 *
 * @param baseType Declared base type of the value to deserializer (actual
 *    deserializer type will be this type or its subtype)
 * 
 * @return Type deserializer to use for given base type, if one is needed; null if not.
 */
public TypeDeserializer findPropertyTypeDeserializer(DeserializationConfig config,
        JavaType baseType, AnnotatedMember annotated)
    throws JsonMappingException
{
    AnnotationIntrospector ai = config.getAnnotationIntrospector();
    TypeResolverBuilder<?> b = ai.findPropertyTypeResolver(config, annotated, baseType);        
    // Defaulting: if no annotations on member, check value class
    if (b == null) {
        return findTypeDeserializer(config, baseType);
    }
    // but if annotations found, may need to resolve subtypes:
    Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByTypeId(
            config, annotated, baseType);
    return b.buildTypeDeserializer(config, baseType, subtypes);
}
 
Example #3
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 #4
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 #5
Source File: PCollectionsCollectionDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
protected T _deserializeContents(JsonParser p, DeserializationContext ctxt)
        throws IOException {
    JsonDeserializer<?> valueDes = _valueDeserializer;
    JsonToken t;
    final TypeDeserializer typeDeser = _typeDeserializerForValue;
    // No way to pass actual type parameter; but does not matter, just
    // compiler-time fluff:
    T collection = createEmptyCollection();

    while ((t = p.nextToken()) != JsonToken.END_ARRAY) {
        Object value;

        if (t == JsonToken.VALUE_NULL) {
            value = null;
        } else if (typeDeser == null) {
            value = valueDes.deserialize(p, ctxt);
        } else {
            value = valueDes.deserializeWithType(p, ctxt, typeDeser);
        }
        // .plus is always overridden to return the correct subclass
        @SuppressWarnings("unchecked")
        T newCollection = (T) collection.plus(value);
        collection = newCollection;
    }
    return collection;
}
 
Example #6
Source File: MapDeserializer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected MapDeserializer(MapDeserializer src,
        KeyDeserializer keyDeser, JsonDeserializer<Object> valueDeser,
        TypeDeserializer valueTypeDeser,
        NullValueProvider nuller,
        Set<String> ignorable)
{
    super(src, nuller, src._unwrapSingle);
    _keyDeserializer = keyDeser;
    _valueDeserializer = valueDeser;
    _valueTypeDeserializer = valueTypeDeser;
    _valueInstantiator = src._valueInstantiator;
    _propertyBasedCreator = src._propertyBasedCreator;
    _delegateDeserializer = src._delegateDeserializer;
    _hasDefaultCreator = src._hasDefaultCreator;
    _ignorableProperties = ignorable;

    _standardStringKey = _isStdKeyDeser(_containerType, keyDeser);
}
 
Example #7
Source File: VavrDeserializers.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
@Override
public JsonDeserializer<?> findCollectionLikeDeserializer(CollectionLikeType collectionType,
                                                          DeserializationConfig config, BeanDescription beanDesc,
                                                          TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
        throws JsonMappingException
{
    Class<?> raw = collectionType.getRawClass();
    if (raw == CharSeq.class) {
        return new CharSeqDeserializer(collectionType);
    }
    if (Seq.class.isAssignableFrom(raw)) {
        return new SeqDeserializer(collectionType, collectionType.getContentType(), elementTypeDeserializer,
                elementDeserializer, settings.deserializeNullAsEmptyCollection());
    }
    if (Set.class.isAssignableFrom(raw)) {
        return new SetDeserializer(collectionType, collectionType.getContentType(), elementTypeDeserializer,
                elementDeserializer, settings.deserializeNullAsEmptyCollection());
    }
    if (PriorityQueue.class.isAssignableFrom(raw)) {
        return new PriorityQueueDeserializer(collectionType, collectionType.getContentType(),
                elementTypeDeserializer, elementDeserializer, settings.deserializeNullAsEmptyCollection());
    }
    return super.findCollectionLikeDeserializer(collectionType, config, beanDesc, elementTypeDeserializer, elementDeserializer);
}
 
Example #8
Source File: FactoryBasedEnumDeserializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException {
    if (_deser == null) { // String never has type info
        return deserialize(p, ctxt);
    }
    return typeDeserializer.deserializeTypedFromAny(p, ctxt);
}
 
Example #9
Source File: SimpleDeserializers.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findCollectionLikeDeserializer(CollectionLikeType type,
        DeserializationConfig config, BeanDescription beanDesc,
        TypeDeserializer elementTypeDeserializer,
        JsonDeserializer<?> elementDeserializer)
    throws JsonMappingException
{
    return _find(type);
}
 
Example #10
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 #11
Source File: ImmutableSortedMapDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public GuavaMapDeserializer<ImmutableSortedMap<Object, Object>> withResolved(KeyDeserializer keyDeser,
        JsonDeserializer<?> valueDeser, TypeDeserializer typeDeser,
        NullValueProvider nuller)
{
    return new ImmutableSortedMapDeserializer(_containerType, keyDeser, valueDeser, typeDeser, nuller);
}
 
Example #12
Source File: ArrayBlockingQueueDeserializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor used when creating contextualized instances.
 */
 protected ArrayBlockingQueueDeserializer(JavaType containerType,
        JsonDeserializer<Object> valueDeser, TypeDeserializer valueTypeDeser,
        ValueInstantiator valueInstantiator,
        JsonDeserializer<Object> delegateDeser,
        NullValueProvider nuller, Boolean unwrapSingle)
{
    super(containerType, valueDeser, valueTypeDeser, valueInstantiator, delegateDeser,
            nuller, unwrapSingle);
}
 
Example #13
Source File: LinkedListMultimapDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
protected JsonDeserializer<?> _createContextual(JavaType type,
        KeyDeserializer keyDeserializer, TypeDeserializer typeDeserializer,
        JsonDeserializer<?> elementDeserializer, Method method, NullValueProvider nvp) {
    return new LinkedListMultimapDeserializer(type, keyDeserializer, typeDeserializer,
            elementDeserializer, method, nvp);
}
 
Example #14
Source File: ArrayListMultimapDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
protected JsonDeserializer<?> _createContextual(JavaType type,
        KeyDeserializer keyDeserializer, TypeDeserializer typeDeserializer,
        JsonDeserializer<?> elementDeserializer, Method method,
        NullValueProvider nvp) {
    return new ArrayListMultimapDeserializer(type, keyDeserializer, typeDeserializer,
            elementDeserializer, method, nvp);
}
 
Example #15
Source File: BeanDeserializerBase.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
        TypeDeserializer typeDeserializer)
    throws IOException
{
    // 16-Feb-2012, tatu: ObjectId may be used as well... need to check that first
    if (_objectIdReader != null) {
        // 05-Aug-2013, tatu: May use native Object Id
        if (p.canReadObjectId()) {
            Object id = p.getObjectId();
            if (id != null) {
                Object ob = typeDeserializer.deserializeTypedFromObject(p, ctxt);
                return _handleTypedObjectId(p, ctxt, ob, id);
            }
        }
        // or, Object Ids Jackson explicitly sets
        JsonToken t = p.getCurrentToken();
        if (t != null) {
            // Most commonly, a scalar (int id, uuid String, ...)
            if (t.isScalarValue()) {
                return deserializeFromObjectId(p, ctxt);
            }
            // but, with 2.5+, a simple Object-wrapped value also legal:
            if (t == JsonToken.START_OBJECT) {
                t = p.nextToken();
            }
            if ((t == JsonToken.FIELD_NAME) && _objectIdReader.maySerializeAsObject()
                    && _objectIdReader.isValidReferencePropertyName(p.getCurrentName(), p)) {
                return deserializeFromObjectId(p, ctxt);
            }
        }
    }
    // In future could check current token... for now this should be enough:
    return typeDeserializer.deserializeTypedFromObject(p, ctxt);
}
 
Example #16
Source File: OptionDeserializer.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
/**
 * Overridable fluent factory method used for creating contextual
 * instances.
 */
private OptionDeserializer withResolved(JavaType refType, TypeDeserializer typeDeser, JsonDeserializer<?> valueDeser) {
    if (refType == valueType && valueDeser == valueDeserializer && typeDeser == valueTypeDeserializer) {
        return this;
    }
    return new OptionDeserializer(this, typeDeser, valueDeser);
}
 
Example #17
Source File: JSR310StringParsableDeserializer.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext context,
        TypeDeserializer deserializer)
    throws IOException
{
    // This is a nasty kludge right here, working around issues like
    // [datatype-jsr310#24]. But should work better than not having the work-around.
    JsonToken t = p.currentToken();
    if ((t != null) && t.isScalarValue()) {
        return deserialize(p, context);
    }
    return deserializer.deserializeTypedFromAny(p, context);
}
 
Example #18
Source File: EnumMapDeserializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public EnumMapDeserializer withResolved(KeyDeserializer keyDeserializer,
        JsonDeserializer<?> valueDeserializer, TypeDeserializer valueTypeDeser,
        NullValueProvider nuller)
{
    if ((keyDeserializer == _keyDeserializer) && (nuller == _nullProvider)
            && (valueDeserializer == _valueDeserializer) && (valueTypeDeser == _valueTypeDeserializer)) {
        return this;
    }
    return new EnumMapDeserializer(this,
            keyDeserializer, valueDeserializer, valueTypeDeser, nuller);
}
 
Example #19
Source File: ObjectArrayDeserializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected ObjectArrayDeserializer(ObjectArrayDeserializer base,
        JsonDeserializer<Object> elemDeser, TypeDeserializer elemTypeDeser,
        NullValueProvider nuller, Boolean unwrapSingle)
{
    super(base, nuller, unwrapSingle);
    _elementClass = base._elementClass;
    _untyped = base._untyped;

    _elementDeserializer = elemDeser;
    _elementTypeDeserializer = elemTypeDeser;
}
 
Example #20
Source File: MutableSetDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
protected Ref withResolved(
        TypeDeserializer typeDeserializerForValue,
        JsonDeserializer<?> valueDeserializer
) {
    return new MutableSetDeserializer.Ref(_elementType, typeDeserializerForValue, valueDeserializer);
}
 
Example #21
Source File: CyclopsDeserializers.java    From cyclops with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findCollectionDeserializer(CollectionType type, DeserializationConfig config, BeanDescription beanDesc, TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer) throws JsonMappingException {
    if (IterableX.class.isAssignableFrom(type.getRawClass())) {
        return new IterableXDeserializer(type.getRawClass(),type.containedTypeOrUnknown(0).getRawClass(),elementTypeDeserializer,elementDeserializer, type);
    }
  return super.findCollectionDeserializer(type, config, beanDesc, elementTypeDeserializer, elementDeserializer);
}
 
Example #22
Source File: ObjectArrayDeserializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object[] deserializeWithType(JsonParser p, DeserializationContext ctxt,
        TypeDeserializer typeDeserializer)
    throws IOException
{
    // Should there be separate handling for base64 stuff?
    // for now this should be enough:
    return (Object[]) typeDeserializer.deserializeTypedFromArray(p, ctxt);
}
 
Example #23
Source File: EnumMapDeserializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 2.9
 */
public EnumMapDeserializer(JavaType mapType, ValueInstantiator valueInst,
        KeyDeserializer keyDeser, JsonDeserializer<?> valueDeser, TypeDeserializer vtd,
        NullValueProvider nuller)
{
    super(mapType, nuller, null);
    _enumClass = mapType.getKeyType().getRawClass();
    _keyDeserializer = keyDeser;
    _valueDeserializer = (JsonDeserializer<Object>) valueDeser;
    _valueTypeDeserializer = vtd;
    _valueInstantiator = valueInst;
}
 
Example #24
Source File: EclipseCollectionsDeserializers.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findMapLikeDeserializer(
        MapLikeType type,
        DeserializationConfig config,
        BeanDescription beanDesc,
        KeyDeserializer keyDeserializer,
        TypeDeserializer elementTypeDeserializer,
        JsonDeserializer<?> elementDeserializer) {
    // TODO: use keyDeserializer, elementTypeDeserializer, and elementDeserializer
    return findBeanDeserializer(type, config, beanDesc);
}
 
Example #25
Source File: Deserializers.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JsonDeserializer<?> findCollectionDeserializer(CollectionType type,
        DeserializationConfig config, BeanDescription beanDesc,
        TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
    throws JsonMappingException
{
    return null;
}
 
Example #26
Source File: StdNodeBasedDeserializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
        TypeDeserializer td)
    throws IOException, JsonProcessingException
{
    /* 19-Nov-2014, tatu: Quite likely we'd have some issues but... let's
     *   try, just in case.
     */
    JsonNode n = (JsonNode) _treeDeserializer.deserializeWithType(jp, ctxt, td);
    return convert(n, ctxt);
}
 
Example #27
Source File: EnumSetDeserializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
        TypeDeserializer typeDeserializer)
    throws IOException, JsonProcessingException
{
    return typeDeserializer.deserializeTypedFromArray(p, ctxt);
}
 
Example #28
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 #29
Source File: CollectionDeserializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor used when creating contextualized instances.
 *
 * @since 2.9
 */
protected CollectionDeserializer(JavaType collectionType,
        JsonDeserializer<Object> valueDeser, TypeDeserializer valueTypeDeser,
        ValueInstantiator valueInstantiator, JsonDeserializer<Object> delegateDeser,
        NullValueProvider nuller, Boolean unwrapSingle)
{
    super(collectionType, nuller, unwrapSingle);
    _valueDeserializer = valueDeser;
    _valueTypeDeserializer = valueTypeDeser;
    _valueInstantiator = valueInstantiator;
    _delegateDeserializer = delegateDeser;
}
 
Example #30
Source File: CollectionDeserializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Fluent-factory method call to construct contextual instance.
     *
     * @since 2.9
     */
    @SuppressWarnings("unchecked")
    protected CollectionDeserializer withResolved(JsonDeserializer<?> dd,
            JsonDeserializer<?> vd, TypeDeserializer vtd,
            NullValueProvider nuller, Boolean unwrapSingle)
    {
//if (true) throw new Error();
        return new CollectionDeserializer(_containerType,
                (JsonDeserializer<Object>) vd, vtd,
                _valueInstantiator, (JsonDeserializer<Object>) dd,
                nuller, unwrapSingle);
    }