Skip to content

Commit

Permalink
Fix #346
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 16, 2013
1 parent 4ec01ea commit 37cf6f2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
4 changes: 4 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
@@ -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: ===
------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,56 @@
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.
*/
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);
Expand Down

0 comments on commit 37cf6f2

Please sign in to comment.