Search in sources :

Example 1 with ObjectIdResolver

use of com.fasterxml.jackson.annotation.ObjectIdResolver 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)

Aggregations

ObjectIdGenerator (com.fasterxml.jackson.annotation.ObjectIdGenerator)1 IdKey (com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey)1 ObjectIdResolver (com.fasterxml.jackson.annotation.ObjectIdResolver)1 ReadableObjectId (com.fasterxml.jackson.databind.deser.impl.ReadableObjectId)1