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 5c4496c052..47888ac369 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 @@ -255,6 +255,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 4e26b4f19f..b245a25dcd 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);