Skip to content

Commit

Permalink
Update notes wrt #353
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 14, 2014
1 parent 9b99cfe commit 5df4c4e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 57 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ Will Palmeri: (wpalmeri@github)
* Contributed #407: Make array and Collection serializers use configured value null handler
(2.4.0)

Cemalettin Koc: (cemo@github)

* Reported #353: Problems with polymorphic types, `JsonNode` (related to #88)
(2.4.0)

2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Version: 2.4.0 (xx-xxx-2014)

#88: Prevent use of type information for `JsonNode` via default typing
(reported by electricmonk@github)
#353: Problems with polymorphic types, `JsonNode` (related to #88)
(reported by cemo@github)
#381: Allow inlining/unwrapping of value from single-component JSON array
(contributed by yinzara@github)
#407: Properly use null handlers for value types when serializer Collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.module.SimpleModule;

public class TestTreeWithType extends BaseMapTest
{
Expand All @@ -18,6 +20,36 @@ public Foo(String bar) {
}
}

// [Issue#353]
public class SavedCookie {
public String name, value;

public SavedCookie() { }
public SavedCookie(String n, String v) {
name = n;
value = v;
}
}

public class SavedCookieDeserializer extends JsonDeserializer<SavedCookie> {
@Override
public SavedCookie deserialize(JsonParser jsonParser, DeserializationContext ctxt)
throws IOException {
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
return new SavedCookie(node.path("name").textValue(),
node.path("value").textValue());
}

@Override
public SavedCookie deserializeWithType(JsonParser jp, DeserializationContext ctxt,
TypeDeserializer typeDeserializer)
throws IOException, JsonProcessingException
{
return (SavedCookie) typeDeserializer.deserializeTypedFromObject(jp, ctxt);
}
}

/*
/**********************************************************
/* Unit tests
Expand Down Expand Up @@ -73,4 +105,22 @@ public void testValueToTreeWithDefaultTyping() throws Exception {
JsonNode jsonNode = mapper.valueToTree(foo);
assertEquals(jsonNode.get("bar").textValue(), foo.bar);
}

public void testIssue353() throws Exception
{
ObjectMapper mapper = new ObjectMapper();

mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.NON_FINAL, "@class");

SimpleModule testModule = new SimpleModule("MyModule", new Version(1, 0, 0, null, "TEST", "TEST"));
testModule.addDeserializer(SavedCookie.class, new SavedCookieDeserializer());
mapper.registerModule(testModule);

SavedCookie savedCookie = new SavedCookie("key", "v");
String json = mapper.writeValueAsString(savedCookie);
SavedCookie out = mapper.reader(SavedCookie.class).readValue(json);

assertEquals("key", out.name);
assertEquals("v", out.value);
}
}
57 changes: 0 additions & 57 deletions src/test/java/com/fasterxml/jackson/failing/TestTreeWithType.java

This file was deleted.

0 comments on commit 5df4c4e

Please sign in to comment.