Skip to content

Commit

Permalink
Fix #941
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 23, 2015
1 parent e258ee6 commit b049739
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,8 @@ Daniel Walker (dsw2127@github)
* Reported, contributed fix for #913: `ObjectMapper.copy()` does not preserve
`MappingJsonFactory` features
(2.6.2)

Sadayuki Furuhashi (frsyuki@github)
* Reported #941: Deserialization from "{}" to ObjectNode field causes
"out of END_OBJECT token" error
(2.6.3)
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Project: jackson-databind

#938: Regression: `StackOverflowError` with recursive types that contain `Map.Entry`
(reported by jloisel@github)
#941: Deserialization from "{}" to ObjectNode field causes "out of END_OBJECT token" error
(reported by Sadayuki F)

2.6.2 (14-Sep-2015)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx
if (_vanillaProcessing) {
return vanillaDeserialize(p, ctxt, p.nextToken());
}
// 23-Sep-2015, tatu: This is wrong at some many levels, but for now... it is
// what it is, including "expected behavior".
p.nextToken();
if (_objectIdReader != null) {
return deserializeWithObjectId(p, ctxt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ final static class ObjectDeserializer
public static ObjectDeserializer getInstance() { return _instance; }

@Override
public ObjectNode deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
public ObjectNode deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
if (jp.getCurrentToken() == JsonToken.START_OBJECT) {
jp.nextToken();
return deserializeObject(jp, ctxt, ctxt.getNodeFactory());
if (p.isExpectedStartObjectToken() || p.hasToken(JsonToken.FIELD_NAME)) {
return deserializeObject(p, ctxt, ctxt.getNodeFactory());
}
if (jp.getCurrentToken() == JsonToken.FIELD_NAME) {
return deserializeObject(jp, ctxt, ctxt.getNodeFactory());
// 23-Sep-2015, tatu: Ugh. We may also be given END_OBJECT (similar to FIELD_NAME),
// if caller has advanced to the first token of Object, but for empty Object
if (p.hasToken(JsonToken.END_OBJECT)) {
return ctxt.getNodeFactory().objectNode();
}
throw ctxt.mappingException(ObjectNode.class);
}
Expand All @@ -117,11 +118,10 @@ final static class ArrayDeserializer
public static ArrayDeserializer getInstance() { return _instance; }

@Override
public ArrayNode deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
public ArrayNode deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
if (jp.isExpectedStartArrayToken()) {
return deserializeArray(jp, ctxt, ctxt.getNodeFactory());
if (p.isExpectedStartArrayToken()) {
return deserializeArray(p, ctxt, ctxt.getNodeFactory());
}
throw ctxt.mappingException(ArrayNode.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@ public ObNodeWrapper(ObjectNode n) {
node = n;
}
}


// [databind#941]
static class MyValue
{
private final ObjectNode object;

@JsonCreator
public MyValue(ObjectNode object) { this.object = object; }

@JsonValue
public ObjectNode getObject() { return object; }
}

/*
/**********************************************************
/* Test methods
Expand Down Expand Up @@ -385,4 +397,18 @@ public void testNonEmptySerialization() throws Exception
w = new ObNodeWrapper(MAPPER.createObjectNode());
assertEquals("{}", MAPPER.writeValueAsString(w));
}

public void testIssue941() throws Exception
{
ObjectNode object = MAPPER.createObjectNode();

String json = MAPPER.writeValueAsString(object);
System.out.println("json: "+json);

ObjectNode de1 = MAPPER.readValue(json, ObjectNode.class); // this works
System.out.println("Deserialized to ObjectNode: "+de1);

MyValue de2 = MAPPER.readValue(json, MyValue.class); // but this throws exception
System.out.println("Deserialized to MyValue: "+de2);
}
}

0 comments on commit b049739

Please sign in to comment.