Skip to content

Commit 37cf6f2

Browse files
committed
Fix #346
1 parent 4ec01ea commit 37cf6f2

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

release-notes/VERSION

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Project: jackson-databind
22
Version: 2.3.1 (xx-Dec-2013)
33

4+
#346: Fix problem deserializing `ObjectNode`, with @JsonCreator, empty
5+
JSON Object
6+
(reported by gaff78@github)
7+
48
------------------------------------------------------------------------
59
=== History: ===
610
------------------------------------------------------------------------

src/main/java/com/fasterxml/jackson/databind/deser/std/JsonNodeDeserializer.java

+1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ protected final JsonNode deserializeAny(JsonParser jp, DeserializationContext ct
274274
{
275275
switch (jp.getCurrentToken()) {
276276
case START_OBJECT:
277+
case END_OBJECT: // for empty JSON Objects we may point to this
277278
return deserializeObject(jp, ctxt, nodeFactory);
278279

279280
case START_ARRAY:

src/test/java/com/fasterxml/jackson/databind/node/TestObjectNode.java

+41-1
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,56 @@
33
import java.math.BigDecimal;
44
import java.util.*;
55

6+
import com.fasterxml.jackson.annotation.JsonCreator;
7+
import com.fasterxml.jackson.annotation.JsonValue;
68
import com.fasterxml.jackson.databind.*;
9+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
710

811
/**
912
* Additional tests for {@link ObjectNode} container class.
1013
*/
1114
public class TestObjectNode
1215
extends BaseMapTest
1316
{
14-
private final ObjectMapper MAPPER = new ObjectMapper();
17+
@JsonDeserialize(as = DataImpl.class)
18+
public interface Data {
19+
}
20+
21+
public static class DataImpl implements Data
22+
{
23+
protected JsonNode root;
24+
25+
@JsonCreator
26+
public DataImpl(JsonNode n) {
27+
root = n;
28+
}
29+
30+
@JsonValue
31+
public JsonNode value() { return root; }
32+
33+
/*
34+
public Wrapper(ObjectNode n) { root = n; }
35+
36+
@JsonValue
37+
public ObjectNode value() { return root; }
38+
*/
39+
}
40+
41+
/*
42+
/**********************************************************
43+
/* Test methods
44+
/**********************************************************
45+
*/
46+
47+
private final ObjectMapper MAPPER = objectMapper();
1548

49+
// for [Issue#346]
50+
public void testEmptyNodeAsValue() throws Exception
51+
{
52+
Data w = MAPPER.readValue("{}", Data.class);
53+
assertNotNull(w);
54+
}
55+
1656
public void testBasics()
1757
{
1858
ObjectNode n = new ObjectNode(JsonNodeFactory.instance);

0 commit comments

Comments
 (0)