Search in sources :

Example 1 with ReadableObjectId

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

the class DefaultDeserializationContext method findObjectId.

/*
    /**********************************************************
    /* Abstract methods impls, Object Id
    /**********************************************************
     */
@Override
public ReadableObjectId findObjectId(Object id, ObjectIdGenerator<?> gen, ObjectIdResolver resolverType) {
    /* 02-Apr-2015, tatu: As per [databind#742] should allow 'null', similar to how
         *   missing id already works.
         */
    if (id == null) {
        return null;
    }
    final ObjectIdGenerator.IdKey key = gen.key(id);
    if (_objectIds == null) {
        _objectIds = new LinkedHashMap<ObjectIdGenerator.IdKey, ReadableObjectId>();
    } else {
        ReadableObjectId entry = _objectIds.get(key);
        if (entry != null) {
            return entry;
        }
    }
    // Not seen yet, must create entry and configure resolver.
    ObjectIdResolver resolver = null;
    if (_objectIdResolvers == null) {
        _objectIdResolvers = new ArrayList<ObjectIdResolver>(8);
    } else {
        for (ObjectIdResolver res : _objectIdResolvers) {
            if (res.canUseFor(resolverType)) {
                resolver = res;
                break;
            }
        }
    }
    if (resolver == null) {
        resolver = resolverType.newForDeserialization(this);
        _objectIdResolvers.add(resolver);
    }
    ReadableObjectId entry = createReadableObjectId(key);
    entry.setResolver(resolver);
    _objectIds.put(key, entry);
    return entry;
}
Also used : IdKey(com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey) ObjectIdGenerator(com.fasterxml.jackson.annotation.ObjectIdGenerator) ReadableObjectId(com.fasterxml.jackson.databind.deser.impl.ReadableObjectId) IdKey(com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey) ObjectIdResolver(com.fasterxml.jackson.annotation.ObjectIdResolver)

Example 2 with ReadableObjectId

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

the class AbstractDeserializer method _deserializeFromObjectId.

/**
     * Method called in cases where it looks like we got an Object Id
     * to parse and use as a reference.
     */
protected Object _deserializeFromObjectId(JsonParser p, DeserializationContext ctxt) throws IOException {
    Object id = _objectIdReader.readObjectReference(p, ctxt);
    ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);
    // do we have it resolved?
    Object pojo = roid.resolve();
    if (pojo == null) {
        // not yet; should wait...
        throw new UnresolvedForwardReference(p, "Could not resolve Object Id [" + id + "] -- unresolved forward-reference?", p.getCurrentLocation(), roid);
    }
    return pojo;
}
Also used : ReadableObjectId(com.fasterxml.jackson.databind.deser.impl.ReadableObjectId)

Example 3 with ReadableObjectId

use of com.fasterxml.jackson.databind.deser.impl.ReadableObjectId in project requery by requery.

the class EntityBeanDeserializer method deserializeFromObject.

@Override
public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) throws IOException {
    if (_nonStandardCreation || _needViewProcesing) {
        return super.deserializeFromObject(p, ctxt);
    }
    Object bean = null;
    if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) {
        String propertyName = p.getCurrentName();
        do {
            p.nextToken();
            SettableBeanProperty property = _beanProperties.find(propertyName);
            if (property == null) {
                handleUnknownVanilla(p, ctxt, bean, propertyName);
                continue;
            }
            // lazily create the bean, the id property must be the first property
            if (bean == null) {
                if (propertyName.equals(_objectIdReader.propertyName.getSimpleName())) {
                    // deserialize id
                    Object id = property.deserialize(p, ctxt);
                    ReadableObjectId objectId = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);
                    bean = objectId == null ? null : objectId.resolve();
                    if (bean == null) {
                        bean = _valueInstantiator.createUsingDefault(ctxt);
                        property.set(bean, id);
                    }
                } else {
                    bean = _valueInstantiator.createUsingDefault(ctxt);
                }
                p.setCurrentValue(bean);
            }
            property.deserializeAndSet(p, ctxt, bean);
        } while ((propertyName = p.nextFieldName()) != null);
    }
    return bean;
}
Also used : ReadableObjectId(com.fasterxml.jackson.databind.deser.impl.ReadableObjectId) SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty)

Example 4 with ReadableObjectId

use of com.fasterxml.jackson.databind.deser.impl.ReadableObjectId 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)

Aggregations

ReadableObjectId (com.fasterxml.jackson.databind.deser.impl.ReadableObjectId)4 IdKey (com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey)2 ObjectIdGenerator (com.fasterxml.jackson.annotation.ObjectIdGenerator)1 ObjectIdResolver (com.fasterxml.jackson.annotation.ObjectIdResolver)1 SettableBeanProperty (com.fasterxml.jackson.databind.deser.SettableBeanProperty)1 Referring (com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring)1