From 37cf6f243424570e39b5f65280ca673089e55945 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 15 Nov 2013 19:31:46 -0800 Subject: [PATCH] Fix #346 --- release-notes/VERSION | 4 ++ .../deser/std/JsonNodeDeserializer.java | 1 + .../jackson/databind/node/TestObjectNode.java | 42 ++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/release-notes/VERSION b/release-notes/VERSION index b15e5f1cb3..2600e1cbf4 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -1,6 +1,10 @@ Project: jackson-databind Version: 2.3.1 (xx-Dec-2013) +#346: Fix problem deserializing `ObjectNode`, with @JsonCreator, empty + JSON Object + (reported by gaff78@github) + ------------------------------------------------------------------------ === History: === ------------------------------------------------------------------------ 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 748979f1dc..11b76b748f 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 @@ -274,6 +274,7 @@ protected final JsonNode deserializeAny(JsonParser jp, DeserializationContext ct { switch (jp.getCurrentToken()) { case START_OBJECT: + case END_OBJECT: // for empty JSON Objects we may point to this return deserializeObject(jp, ctxt, nodeFactory); case START_ARRAY: diff --git a/src/test/java/com/fasterxml/jackson/databind/node/TestObjectNode.java b/src/test/java/com/fasterxml/jackson/databind/node/TestObjectNode.java index aa67b47f80..bcf7945fbf 100644 --- a/src/test/java/com/fasterxml/jackson/databind/node/TestObjectNode.java +++ b/src/test/java/com/fasterxml/jackson/databind/node/TestObjectNode.java @@ -3,7 +3,10 @@ import java.math.BigDecimal; import java.util.*; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; /** * Additional tests for {@link ObjectNode} container class. @@ -11,8 +14,45 @@ public class TestObjectNode extends BaseMapTest { - private final ObjectMapper MAPPER = new ObjectMapper(); + @JsonDeserialize(as = DataImpl.class) + public interface Data { + } + + public static class DataImpl implements Data + { + protected JsonNode root; + + @JsonCreator + public DataImpl(JsonNode n) { + root = n; + } + + @JsonValue + public JsonNode value() { return root; } + + /* + public Wrapper(ObjectNode n) { root = n; } + + @JsonValue + public ObjectNode value() { return root; } + */ + } + + /* + /********************************************************** + /* Test methods + /********************************************************** + */ + + private final ObjectMapper MAPPER = objectMapper(); + // for [Issue#346] + public void testEmptyNodeAsValue() throws Exception + { + Data w = MAPPER.readValue("{}", Data.class); + assertNotNull(w); + } + public void testBasics() { ObjectNode n = new ObjectNode(JsonNodeFactory.instance);