1
- package com .fasterxml .jackson .failing ;
1
+ package com .fasterxml .jackson .databind . jsontype ;
2
2
3
3
import com .fasterxml .jackson .annotation .JsonTypeInfo ;
4
4
import com .fasterxml .jackson .databind .*;
5
5
6
- public class TestNodeTypingIssue88 extends BaseMapTest
6
+ public class TestDefaultForTreeNodes extends BaseMapTest
7
7
{
8
8
public static class Foo {
9
9
public String bar ;
@@ -17,26 +17,25 @@ public Foo() { }
17
17
/* Unit tests
18
18
/**********************************************************
19
19
*/
20
+
21
+ private final ObjectMapper DEFAULT_MAPPER = new ObjectMapper ();
22
+ {
23
+ DEFAULT_MAPPER .enableDefaultTyping (ObjectMapper .DefaultTyping .NON_FINAL , JsonTypeInfo .As .PROPERTY );
24
+ }
20
25
21
26
public void testValueAsStringWithDefaultTyping () throws Exception
22
27
{
23
- ObjectMapper mapper = new ObjectMapper ();
24
- mapper .enableDefaultTyping (ObjectMapper .DefaultTyping .NON_FINAL , JsonTypeInfo .As .PROPERTY );
25
-
26
28
Foo foo = new Foo ("baz" );
27
- String json = mapper .writeValueAsString (foo );
29
+ String json = DEFAULT_MAPPER .writeValueAsString (foo );
28
30
29
- JsonNode jsonNode = mapper .readTree (json );
31
+ JsonNode jsonNode = DEFAULT_MAPPER .readTree (json );
30
32
assertEquals (jsonNode .get ("bar" ).textValue (), foo .bar );
31
33
}
32
34
33
35
public void testValueToTreeWithDefaultTyping () throws Exception
34
36
{
35
- ObjectMapper mapper = new ObjectMapper ();
36
- mapper .enableDefaultTyping (ObjectMapper .DefaultTyping .NON_FINAL , JsonTypeInfo .As .PROPERTY );
37
-
38
37
Foo foo = new Foo ("baz" );
39
- JsonNode jsonNode = mapper .valueToTree (foo );
38
+ JsonNode jsonNode = DEFAULT_MAPPER .valueToTree (foo );
40
39
assertEquals (jsonNode .get ("bar" ).textValue (), foo .bar );
41
40
}
42
41
}
0 commit comments