8
8
9
9
import com .fasterxml .jackson .core .type .TypeReference ;
10
10
import com .fasterxml .jackson .databind .ObjectMapper ;
11
+ import com .fasterxml .jackson .databind .json .JsonMapper ;
12
+
11
13
import org .junit .Assert ;
12
- import org .junit .Before ;
13
14
import org .junit .Test ;
14
15
15
16
public class TestOffsetDateTimeKeySerialization {
@@ -23,23 +24,13 @@ public class TestOffsetDateTimeKeySerialization {
23
24
private static final OffsetDateTime DATE_TIME_2 = OffsetDateTime .of (2015 , 3 , 14 , 9 , 26 , 53 , 590 * 1000 * 1000 , ZoneOffset .ofHours (6 ));
24
25
private static final String DATE_TIME_2_STRING = "2015-03-14T09:26:53.590+06:00" ;
25
26
26
- private ObjectMapper om ;
27
- private Map <OffsetDateTime , String > map ;
28
-
29
- @ Before
30
- public void setUp () {
31
- om = ObjectMapper .builder ()
32
- .addModule (new JavaTimeModule ())
33
- .build ();
34
- map = new HashMap <>();
35
- }
36
-
37
- /*
38
- * ObjectMapper configuration is not respected at deserialization and serialization at the moment.
39
- */
27
+ private ObjectMapper om = JsonMapper .builder ()
28
+ .addModule (new JavaTimeModule ())
29
+ .build ();
40
30
41
31
@ Test
42
32
public void testSerialization0 () throws Exception {
33
+ Map <OffsetDateTime , String > map = new HashMap <>();
43
34
map .put (DATE_TIME_0 , "test" );
44
35
45
36
String value = om .writeValueAsString (map );
@@ -49,6 +40,7 @@ public void testSerialization0() throws Exception {
49
40
50
41
@ Test
51
42
public void testSerialization1 () throws Exception {
43
+ Map <OffsetDateTime , String > map = new HashMap <>();
52
44
map .put (DATE_TIME_1 , "test" );
53
45
54
46
String value = om .writeValueAsString (map );
@@ -58,6 +50,7 @@ public void testSerialization1() throws Exception {
58
50
59
51
@ Test
60
52
public void testSerialization2 () throws Exception {
53
+ Map <OffsetDateTime , String > map = new HashMap <>();
61
54
map .put (DATE_TIME_2 , "test" );
62
55
63
56
String value = om .writeValueAsString (map );
@@ -69,6 +62,7 @@ public void testSerialization2() throws Exception {
69
62
public void testDeserialization0 () throws Exception {
70
63
Map <OffsetDateTime , String > value = om .readValue (map (DATE_TIME_0_STRING , "test" ), TYPE_REF );
71
64
65
+ Map <OffsetDateTime , String > map = new HashMap <>();
72
66
map .put (DATE_TIME_0 , "test" );
73
67
Assert .assertEquals ("Value is incorrect" , map , value );
74
68
}
@@ -77,6 +71,7 @@ public void testDeserialization0() throws Exception {
77
71
public void testDeserialization1 () throws Exception {
78
72
Map <OffsetDateTime , String > value = om .readValue (map (DATE_TIME_1_STRING , "test" ), TYPE_REF );
79
73
74
+ Map <OffsetDateTime , String > map = new HashMap <>();
80
75
map .put (DATE_TIME_1 , "test" );
81
76
Assert .assertEquals ("Value is incorrect" , map , value );
82
77
}
@@ -85,12 +80,12 @@ public void testDeserialization1() throws Exception {
85
80
public void testDeserialization2 () throws Exception {
86
81
Map <OffsetDateTime , String > value = om .readValue (map (DATE_TIME_2_STRING , "test" ), TYPE_REF );
87
82
83
+ Map <OffsetDateTime , String > map = new HashMap <>();
88
84
map .put (DATE_TIME_2 , "test" );
89
85
Assert .assertEquals ("Value is incorrect" , map , value );
90
86
}
91
87
92
88
private String map (String key , String value ) {
93
89
return String .format ("{\" %s\" :\" %s\" }" , key , value );
94
90
}
95
-
96
91
}
0 commit comments