Search in sources :

Example 1 with Referring

use of com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring in project jackson-databind by FasterXML.

the class CollectionDeserializer method deserialize.

@Override
public Collection<Object> deserialize(JsonParser p, DeserializationContext ctxt, Collection<Object> result) throws IOException {
    // Ok: must point to START_ARRAY (or equivalent)
    if (!p.isExpectedStartArrayToken()) {
        return handleNonArray(p, ctxt, result);
    }
    // [databind#631]: Assign current value, to be accessible by custom serializers
    p.setCurrentValue(result);
    JsonDeserializer<Object> valueDes = _valueDeserializer;
    final TypeDeserializer typeDeser = _valueTypeDeserializer;
    CollectionReferringAccumulator referringAccumulator = (valueDes.getObjectIdReader() == null) ? null : new CollectionReferringAccumulator(_containerType.getContentType().getRawClass(), result);
    JsonToken t;
    while ((t = p.nextToken()) != JsonToken.END_ARRAY) {
        try {
            Object value;
            if (t == JsonToken.VALUE_NULL) {
                if (_skipNullValues) {
                    continue;
                }
                value = _nullProvider.getNullValue(ctxt);
            } else if (typeDeser == null) {
                value = valueDes.deserialize(p, ctxt);
            } else {
                value = valueDes.deserializeWithType(p, ctxt, typeDeser);
            }
            if (referringAccumulator != null) {
                referringAccumulator.add(value);
            } else {
                result.add(value);
            }
        } catch (UnresolvedForwardReference reference) {
            if (referringAccumulator == null) {
                throw JsonMappingException.from(p, "Unresolved forward reference but no identity info", reference);
            }
            Referring ref = referringAccumulator.handleUnresolvedReference(reference);
            reference.getRoid().appendReferring(ref);
        } catch (Exception e) {
            boolean wrap = (ctxt == null) || ctxt.isEnabled(DeserializationFeature.WRAP_EXCEPTIONS);
            if (!wrap) {
                ClassUtil.throwIfRTE(e);
            }
            throw JsonMappingException.wrapWithPath(e, result, result.size());
        }
    }
    return result;
}
Also used : Referring(com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring) TypeDeserializer(com.fasterxml.jackson.databind.jsontype.TypeDeserializer) IOException(java.io.IOException)

Example 2 with Referring

use of com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring in project jackson-databind by FasterXML.

the class DefaultDeserializationContext method checkUnresolvedObjectId.

@Override
public void checkUnresolvedObjectId() throws UnresolvedForwardReference {
    if (_objectIds == null) {
        return;
    }
    // 29-Dec-2014, tatu: As per [databind#299], may also just let unresolved refs be...
    if (!isEnabled(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS)) {
        return;
    }
    UnresolvedForwardReference exception = null;
    for (Entry<IdKey, ReadableObjectId> entry : _objectIds.entrySet()) {
        ReadableObjectId roid = entry.getValue();
        if (!roid.hasReferringProperties()) {
            continue;
        }
        // as per [databind#675], allow resolution at this point
        if (tryToResolveUnresolvedObjectId(roid)) {
            continue;
        }
        if (exception == null) {
            exception = new UnresolvedForwardReference(getParser(), "Unresolved forward references for: ");
        }
        Object key = roid.getKey().key;
        for (Iterator<Referring> iterator = roid.referringProperties(); iterator.hasNext(); ) {
            Referring referring = iterator.next();
            exception.addUnresolvedId(key, referring.getBeanType(), referring.getLocation());
        }
    }
    if (exception != null) {
        throw exception;
    }
}
Also used : ReadableObjectId(com.fasterxml.jackson.databind.deser.impl.ReadableObjectId) Referring(com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring) IdKey(com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey)

Example 3 with Referring

use of com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring in project jackson-databind by FasterXML.

the class MapDeserializer method handleUnresolvedReference.

private void handleUnresolvedReference(DeserializationContext ctxt, MapReferringAccumulator accumulator, Object key, UnresolvedForwardReference reference) throws JsonMappingException {
    if (accumulator == null) {
        ctxt.reportInputMismatch(this, "Unresolved forward reference but no identity info: " + reference);
    }
    Referring referring = accumulator.handleUnresolvedReference(reference, key);
    reference.getRoid().appendReferring(referring);
}
Also used : Referring(com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring)

Aggregations

Referring (com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring)3 IdKey (com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey)1 ReadableObjectId (com.fasterxml.jackson.databind.deser.impl.ReadableObjectId)1 TypeDeserializer (com.fasterxml.jackson.databind.jsontype.TypeDeserializer)1 IOException (java.io.IOException)1