-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f7358f
commit 8221fe1
Showing
2 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/com/fasterxml/jackson/failing/TestNodeTypingIssue88.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.databind.*; | ||
|
||
public class TestNodeTypingIssue88 extends BaseMapTest | ||
{ | ||
public static class Foo { | ||
public String bar; | ||
|
||
public Foo() { } | ||
public Foo(String b) { bar = b; } | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Unit tests | ||
/********************************************************** | ||
*/ | ||
|
||
public void testValueAsStringWithDefaultTyping() throws Exception | ||
{ | ||
ObjectMapper mapper = new ObjectMapper(); | ||
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY); | ||
|
||
Foo foo = new Foo("baz"); | ||
String json = mapper.writeValueAsString(foo); | ||
|
||
JsonNode jsonNode = mapper.readTree(json); | ||
assertEquals(jsonNode.get("bar").textValue(), foo.bar); | ||
} | ||
|
||
public void testValueToTreeWithDefaultTyping() throws Exception | ||
{ | ||
ObjectMapper mapper = new ObjectMapper(); | ||
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY); | ||
|
||
Foo foo = new Foo("baz"); | ||
JsonNode jsonNode = mapper.valueToTree(foo); | ||
assertEquals(jsonNode.get("bar").textValue(), foo.bar); | ||
} | ||
} |