Skip to content

Commit

Permalink
Fix #433
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 5, 2014
1 parent f939634 commit d222b0b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
4 changes: 3 additions & 1 deletion release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Version: 2.3.3 (xx-xxx-2014)
#422: Allow use of "True" and "False" as aliases for booleans when coercing from
JSON String
#423: Fix `CalendarSerializer` to work with custom format
(repored by sergeymetallic@github)
(reported by sergeymetallic@github)
#433: `ObjectMapper`'s `.valueToTree()` wraps `JsonSerializable` objects into a POJONode
(reported by Francis G)
- Fix null-handling for `CollectionSerializer`

------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ protected final JsonNode deserializeAny(JsonParser jp, DeserializationContext ct
if (type == byte[].class) { // most common special case
return nodeFactory.binaryNode((byte[]) ob);
}
if (JsonNode.class.isAssignableFrom(type)) {
// [Issue#433]: but could also be a JsonNode hiding in there!
return (JsonNode) ob;
}
// any other special handling needed?
return nodeFactory.pojoNode(ob);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import org.junit.Assert;

import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.util.TokenBuffer;

/**
Expand Down Expand Up @@ -43,7 +43,7 @@ public static class LeafMixIn
/**********************************************************
*/

private final static ObjectMapper MAPPER = new ObjectMapper();
private final ObjectMapper MAPPER = objectMapper();

public void testAsInt() throws Exception
{
Expand Down Expand Up @@ -200,8 +200,7 @@ public void testEmbeddedObjectInObject() throws Exception
}

// [Issue#232]
public void testBigDecimalAsPlainStringTreeConversion()
throws Exception
public void testBigDecimalAsPlainStringTreeConversion() throws Exception
{
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN);
Expand All @@ -213,5 +212,38 @@ public void testBigDecimalAsPlainStringTreeConversion()
assertEquals(1, tree.size());
assertTrue(tree.has("pi"));
}

static class CustomSerializedPojo implements JsonSerializable
{
private final ObjectNode node = JsonNodeFactory.instance.objectNode();

public void setFoo(final String foo) {
node.put("foo", foo);
}

@Override
public void serialize(final JsonGenerator jgen, final SerializerProvider provider)
throws IOException
{
jgen.writeTree(node);
}

@Override
public void serializeWithType(JsonGenerator jgen,
SerializerProvider provider, TypeSerializer typeSer) throws IOException {
typeSer.writeTypePrefixForObject(this, jgen);
serialize(jgen, provider);
typeSer.writeTypeSuffixForObject(this, jgen);
}
}

// [Issue#433]
public void testBeanToTree() throws Exception
{
final CustomSerializedPojo pojo = new CustomSerializedPojo();
pojo.setFoo("bar");
final JsonNode node = MAPPER.valueToTree(pojo);
assertEquals(JsonNodeType.OBJECT, node.getNodeType());
}
}

0 comments on commit d222b0b

Please sign in to comment.