aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java
diff options
context:
space:
mode:
authorPascal Gélinas <pascal.gelinas@nuecho.com>2013-12-12 10:12:24 -0500
committerPascal Gélinas <pascal.gelinas@nuecho.com>2014-01-13 10:07:33 -0500
commitdea828df2e34710556f300cf3a5a509f23af7767 (patch)
treead9e6601b1aa59bc47efc9d37043e4f6bd47c847 /src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java
parentd823407ab82164afdd14832fe5159c44d42d89ef (diff)
downloadjackson-databind-dea828df2e34710556f300cf3a5a509f23af7767.tar.gz
Implemented forward reference resolution for any setter based deserialization.
Diffstat (limited to 'src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java')
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java b/src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java
index 794cd9f61..70e563ede 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java
@@ -5,6 +5,7 @@ import java.lang.reflect.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
@@ -106,7 +107,15 @@ public class SettableAnyProperty
Object instance, String propName)
throws IOException, JsonProcessingException
{
- set(instance, propName, deserialize(jp, ctxt));
+ try {
+ set(instance, propName, deserialize(jp, ctxt));
+ } catch (UnresolvedForwardReference reference) {
+ if (!(_valueDeserializer.getObjectIdReader() != null)) {
+ throw JsonMappingException.from(jp, "Unresolved forward reference but no identity info.", reference);
+ }
+ AnySetterReferring referring = new AnySetterReferring(instance, propName, reference.getUnresolvedId());
+ reference.getRoid().appendReferring(referring);
+ }
}
public Object deserialize(JsonParser jp, DeserializationContext ctxt)
@@ -177,6 +186,30 @@ public class SettableAnyProperty
@Override public String toString() { return "[any property on class "+getClassName()+"]"; }
+ private class AnySetterReferring implements Referring {
+ private Object _pojo;
+ private String _propName;
+ private Object _unresolvedId;
+
+ public AnySetterReferring(Object instance, String propName, Object id)
+ {
+ _pojo = instance;
+ _propName = propName;
+ _unresolvedId = id;
+ }
+
+ @Override
+ public void handleResolvedForwardReference(Object id, Object value)
+ throws IOException
+ {
+ if (!id.equals(_unresolvedId)) {
+ throw new IllegalArgumentException("Trying to resolve a forward reference with id [" + id.toString()
+ + "] that wasn't previously registered.");
+ }
+ set(_pojo, _propName, value);
+ }
+ }
+
/*
/**********************************************************
/* JDK serialization handling