com.fasterxml.jackson.databind.deser.DefaultDeserializationContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swagger-all Show documentation
Show all versions of swagger-all Show documentation
swagger-all is a rebundled verison of Swagger as one OSGi bundle.
package com.fasterxml.jackson.databind.deser;
import java.util.*;
import java.util.Map.Entry;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdResolver;
import com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey;
import com.fasterxml.jackson.annotation.SimpleObjectIdResolver;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.util.ClassUtil;
/**
* Complete {@link DeserializationContext} implementation that adds
* extended API for {@link ObjectMapper} (and {@link ObjectReader})
* to call, as well as implements certain parts that base class
* has left abstract.
* The remaining abstract methods ({@link #createInstance}, {@link #with})
* are left so that custom implementations will properly implement them
* to return intended subtype.
*/
public abstract class DefaultDeserializationContext
extends DeserializationContext
implements java.io.Serializable // since 2.1
{
private static final long serialVersionUID = 1L;
protected transient LinkedHashMap _objectIds;
private List _objectIdResolvers;
/**
* Constructor that will pass specified deserializer factory and
* cache: cache may be null (in which case default implementation
* will be used), factory can not be null
*/
protected DefaultDeserializationContext(DeserializerFactory df, DeserializerCache cache) {
super(df, cache);
}
protected DefaultDeserializationContext(DefaultDeserializationContext src,
DeserializationConfig config, JsonParser jp, InjectableValues values) {
super(src, config, jp, values);
}
protected DefaultDeserializationContext(DefaultDeserializationContext src,
DeserializerFactory factory) {
super(src, factory);
}
/**
* @since 2.4.4
*/
protected DefaultDeserializationContext(DefaultDeserializationContext src) {
super(src);
}
/**
* Method needed to ensure that {@link ObjectMapper#copy} will work
* properly; specifically, that caches are cleared, but settings
* will otherwise remain identical; and that no sharing of state
* occurs.
*
* @since 2.4.4
*/
public DefaultDeserializationContext copy() {
throw new IllegalStateException("DefaultDeserializationContext sub-class not overriding copy()");
}
/*
/**********************************************************
/* Abstract methods impls, Object Id
/**********************************************************
*/
@Override
public ReadableObjectId findObjectId(Object id, ObjectIdGenerator> gen, ObjectIdResolver resolverType)
{
final ObjectIdGenerator.IdKey key = gen.key(id);
if (_objectIds == null) {
_objectIds = new LinkedHashMap();
} 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(8);
} else {
for (ObjectIdResolver res : _objectIdResolvers) {
if (res.canUseFor(resolverType)) {
resolver = res;
break;
}
}
}
if (resolver == null) {
resolver = resolverType.newForDeserialization(this);
/* !!! 18-Jun-2014, pgelinas: Temporary fix for [#490] until real
* fix (for jackson-annotations, SimpleObjectIdResolver) can be added.
*/
if (resolverType instanceof SimpleObjectIdResolver) {
resolver = new SimpleObjectIdResolver();
}
_objectIdResolvers.add(resolver);
}
ReadableObjectId entry = new ReadableObjectId(key);
entry.setResolver(resolver);
_objectIds.put(key, entry);
return entry;
}
@Deprecated // since 2.4
@Override
public ReadableObjectId findObjectId(Object id, ObjectIdGenerator> gen) {
return findObjectId(id, gen, new SimpleObjectIdResolver());
}
@Override
public void checkUnresolvedObjectId() throws UnresolvedForwardReference
{
if (_objectIds == null) {
return;
}
UnresolvedForwardReference exception = null;
for (Entry entry : _objectIds.entrySet()) {
ReadableObjectId roid = entry.getValue();
if (roid.hasReferringProperties()) {
if (exception == null) {
exception = new UnresolvedForwardReference("Unresolved forward references for: ");
}
for (Iterator iterator = roid.referringProperties(); iterator.hasNext();) {
Referring referring = iterator.next();
exception.addUnresolvedId(roid.getKey().key, referring.getBeanType(), referring.getLocation());
}
}
}
if (exception != null) {
throw exception;
}
}
/*
/**********************************************************
/* Abstract methods impls, other factory methods
/**********************************************************
*/
@SuppressWarnings("unchecked")
@Override
public JsonDeserializer