Fixing {Object,Array}Deserializer's illegal nullValue
diff --git a/.gitignore b/.gitignore
index 5e3e8df..1271c27 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,6 +16,7 @@
.settings
# IDEA
+.idea
*.iml
*.ipr
*.iws
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/JsonNodeDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/JsonNodeDeserializer.java
index 833b58f..748979f 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/std/JsonNodeDeserializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/JsonNodeDeserializer.java
@@ -13,7 +13,7 @@
*/
@SuppressWarnings("serial")
public class JsonNodeDeserializer
- extends BaseNodeDeserializer
+ extends BaseNodeDeserializer<JsonNode>
{
/**
* Singleton instance of generic deserializer for {@link JsonNode}.
@@ -21,7 +21,7 @@
*/
private final static JsonNodeDeserializer instance = new JsonNodeDeserializer();
- protected JsonNodeDeserializer() { }
+ protected JsonNodeDeserializer() { super(JsonNode.class); }
/**
* Factory method for accessing deserializer for specific node type
@@ -44,6 +44,11 @@
/**********************************************************
*/
+ @Override
+ public JsonNode getNullValue() {
+ return NullNode.getInstance();
+ }
+
/**
* Implementation that will produce types of any JSON nodes; not just one
* deserializer is registered to handle (in case of more specialized handler).
@@ -70,13 +75,13 @@
*/
final static class ObjectDeserializer
- extends BaseNodeDeserializer
+ extends BaseNodeDeserializer<ObjectNode>
{
private static final long serialVersionUID = 1L;
protected final static ObjectDeserializer _instance = new ObjectDeserializer();
- protected ObjectDeserializer() { }
+ protected ObjectDeserializer() { super(ObjectNode.class); }
public static ObjectDeserializer getInstance() { return _instance; }
@@ -96,13 +101,13 @@
}
final static class ArrayDeserializer
- extends BaseNodeDeserializer
+ extends BaseNodeDeserializer<ArrayNode>
{
private static final long serialVersionUID = 1L;
protected final static ArrayDeserializer _instance = new ArrayDeserializer();
- protected ArrayDeserializer() { }
+ protected ArrayDeserializer() { super(ArrayNode.class); }
public static ArrayDeserializer getInstance() { return _instance; }
@@ -123,12 +128,12 @@
* implementations
*/
@SuppressWarnings("serial")
-abstract class BaseNodeDeserializer
- extends StdDeserializer<JsonNode>
+abstract class BaseNodeDeserializer<T extends JsonNode>
+ extends StdDeserializer<T>
{
- public BaseNodeDeserializer()
+ public BaseNodeDeserializer(Class<T> vc)
{
- super(JsonNode.class);
+ super(vc);
}
@Override
@@ -142,16 +147,6 @@
return typeDeserializer.deserializeTypedFromAny(jp, ctxt);
}
- @Override
- public JsonNode getNullValue() {
- return NullNode.getInstance();
- }
-
- @Override
- public Class<?> handledType() {
- return JsonNode.class;
- }
-
/*
/**********************************************************
/* Overridable methods
diff --git a/src/test/java/com/fasterxml/jackson/databind/node/TestTreeDeserialization.java b/src/test/java/com/fasterxml/jackson/databind/node/TestTreeDeserialization.java
index 1f88848..0c88cdc 100644
--- a/src/test/java/com/fasterxml/jackson/databind/node/TestTreeDeserialization.java
+++ b/src/test/java/com/fasterxml/jackson/databind/node/TestTreeDeserialization.java
@@ -1,8 +1,9 @@
package com.fasterxml.jackson.databind.node;
-import java.io.*;
-
-import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.BaseMapTest;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
/**
* This unit test suite tries to verify that JsonNode-based trees
@@ -115,4 +116,24 @@
assertNotNull(n);
assertTrue(n.isNull());
}
+
+ final static class CovarianceBean {
+ ObjectNode _object;
+ ArrayNode _array;
+
+ public void setObject(ObjectNode n) { _object = n; }
+ public void setArray(ArrayNode n) { _array = n; }
+ }
+
+ public void testNullHandlingCovariance() throws Exception
+ {
+ String JSON = "{\"object\" : null, \"array\" : null }";
+ CovarianceBean bean = objectMapper().readValue(JSON, CovarianceBean.class);
+
+ ObjectNode on = bean._object;
+ assertNull(on);
+
+ ArrayNode an = bean._array;
+ assertNull(an);
+ }
}