Skip to content

Commit 7e10ce0

Browse files
committed
backport #346 fix for 2.2.4
1 parent 2a0c770 commit 7e10ce0

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ protected final JsonNode deserializeAny(JsonParser jp, DeserializationContext ct
255255
{
256256
switch (jp.getCurrentToken()) {
257257
case START_OBJECT:
258+
case END_OBJECT: // for empty JSON Objects we may point to this
258259
return deserializeObject(jp, ctxt, nodeFactory);
259260

260261
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)