Improve handling of polymorphic types, wrt updatingReader
diff --git a/release-notes/VERSION b/release-notes/VERSION
index cfffe0e..36db279 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -8,6 +8,7 @@
* [JACKSON-887]: StackOverflow with parameterized sub-class field
(reported by Alexander M)
* [JACKSON-889]: Parsing error in 'nextFieldName()'
+* ???: Add support for updating values of polymorphic types.
------------------------------------------------------------------------
=== History: ===
diff --git a/src/mapper/java/org/codehaus/jackson/map/JsonDeserializer.java b/src/mapper/java/org/codehaus/jackson/map/JsonDeserializer.java
index fe71740..b986b71 100644
--- a/src/mapper/java/org/codehaus/jackson/map/JsonDeserializer.java
+++ b/src/mapper/java/org/codehaus/jackson/map/JsonDeserializer.java
@@ -61,7 +61,8 @@
T intoValue)
throws IOException, JsonProcessingException
{
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("Can not update object of type "
+ +intoValue.getClass().getName()+" (by deserializer of type "+getClass().getName()+")");
}
/**
diff --git a/src/mapper/java/org/codehaus/jackson/map/deser/StdDeserializerProvider.java b/src/mapper/java/org/codehaus/jackson/map/deser/StdDeserializerProvider.java
index 6fc6c2c..c59b99d 100644
--- a/src/mapper/java/org/codehaus/jackson/map/deser/StdDeserializerProvider.java
+++ b/src/mapper/java/org/codehaus/jackson/map/deser/StdDeserializerProvider.java
@@ -469,6 +469,16 @@
// should never happen? (if it can, could call on that object)
throw new IllegalStateException("Type-wrapped deserializer's deserializeWithType should never get called");
}
- }
+ @Override
+ public Object deserialize(JsonParser jp, DeserializationContext ctxt,
+ Object intoValue)
+ throws IOException, JsonProcessingException
+ {
+ /* 01-Mar-2013, tatu: Hmmh. Tough call as to what to do... need
+ * to delegate, but will this work reliably? Let's just hope so:
+ */
+ return _deserializer.deserialize(jp, ctxt, intoValue);
+ }
+ }
}
diff --git a/src/test/org/codehaus/jackson/map/convert/TestPolymorphicUpdateValue.java b/src/test/org/codehaus/jackson/map/convert/TestPolymorphicUpdateValue.java
new file mode 100644
index 0000000..7201f85
--- /dev/null
+++ b/src/test/org/codehaus/jackson/map/convert/TestPolymorphicUpdateValue.java
@@ -0,0 +1,45 @@
+package org.codehaus.jackson.map.convert;
+
+import org.codehaus.jackson.annotate.*;
+
+import org.codehaus.jackson.map.*;
+
+/**
+ * Unit tests for verifying handling of update value on polymorphic
+ * objects.
+ */
+public class TestPolymorphicUpdateValue extends BaseMapTest
+{
+ @JsonTypeInfo(include=JsonTypeInfo.As.WRAPPER_ARRAY //PROPERTY
+ ,use=JsonTypeInfo.Id.NAME, property="type")
+ @JsonSubTypes(value={ @JsonSubTypes.Type(value=Child.class)})
+ abstract static class Parent {
+ public int x;
+ public int y;
+ }
+
+ @JsonTypeName("child")
+ public static class Child extends Parent {
+ public int w;
+ public int h;
+ }
+
+ /*
+ /********************************************************
+ /* Unit tests
+ /********************************************************
+ */
+
+ private final ObjectMapper MAPPER = new ObjectMapper();
+
+ public void testPolymorphicTest() throws Exception
+ {
+ Child c = new Child();
+ c.w = 10;
+ c.h = 11;
+ MAPPER.readerForUpdating(c).readValue("{\"x\":3,\"y\":4,\"w\":111}");
+ assertEquals(3, c.x);
+ assertEquals(4, c.y);
+ assertEquals(111, c.w);
+ }
+}