15
15
public class MiscJavaXMLTypesReadWriteTest
16
16
extends BaseMapTest
17
17
{
18
+ private final ObjectMapper MAPPER = newJsonMapper ();
19
+
18
20
/*
19
21
/**********************************************************
20
22
/* Serializer tests
@@ -40,19 +42,17 @@ public void testXMLGregorianCalendarSerAndDeser() throws Exception
40
42
DatatypeFactory dtf = DatatypeFactory .newInstance ();
41
43
XMLGregorianCalendar cal = dtf .newXMLGregorianCalendar
42
44
(1974 , 10 , 10 , 18 , 15 , 17 , 123 , 0 );
43
- /* Due to [JACKSON-308], 1.6 will use configurable Date serialization;
44
- * and it defaults to using timestamp. So let's try couple of combinations.
45
- */
46
- ObjectMapper mapper = new ObjectMapper ();
45
+
47
46
long timestamp = cal .toGregorianCalendar ().getTimeInMillis ();
48
47
String numStr = String .valueOf (timestamp );
49
- assertEquals (numStr , mapper .writeValueAsString (cal ));
48
+ assertEquals (numStr , MAPPER .writeValueAsString (cal ));
50
49
51
50
// [JACKSON-403] Needs to come back ok as well:
52
- XMLGregorianCalendar calOut = mapper .readValue (numStr , XMLGregorianCalendar .class );
51
+ XMLGregorianCalendar calOut = MAPPER .readValue (numStr , XMLGregorianCalendar .class );
53
52
assertNotNull (calOut );
54
53
assertEquals (timestamp , calOut .toGregorianCalendar ().getTimeInMillis ());
55
54
55
+ ObjectMapper mapper = new ObjectMapper ();
56
56
// and then textual variant
57
57
mapper .configure (SerializationFeature .WRITE_DATES_AS_TIMESTAMPS , false );
58
58
// this is ALMOST same as default for XMLGregorianCalendar... just need to unify Z/+0000
@@ -97,9 +97,8 @@ public void testQNameDeser() throws Exception
97
97
{
98
98
QName qn = new QName ("http://abc" , "tag" , "prefix" );
99
99
String qstr = qn .toString ();
100
- ObjectMapper mapper = new ObjectMapper ();
101
100
assertEquals ("Should deserialize to equal QName (exp serialization: '" +qstr +"')" ,
102
- qn , mapper .readValue (q (qstr ), QName .class ));
101
+ qn , MAPPER .readValue (q (qstr ), QName .class ));
103
102
}
104
103
105
104
public void testCalendarDeser () throws Exception
@@ -109,7 +108,7 @@ public void testCalendarDeser() throws Exception
109
108
(1974 , 10 , 10 , 18 , 15 , 17 , 123 , 0 );
110
109
String exp = cal .toXMLFormat ();
111
110
assertEquals ("Should deserialize to equal XMLGregorianCalendar ('" +exp +"')" , cal ,
112
- new ObjectMapper () .readValue (q (exp ), XMLGregorianCalendar .class ));
111
+ MAPPER .readValue (q (exp ), XMLGregorianCalendar .class ));
113
112
}
114
113
115
114
public void testDurationDeser () throws Exception
@@ -119,6 +118,6 @@ public void testDurationDeser() throws Exception
119
118
Duration dur = dtf .newDurationDayTime (true , 27 , 5 , 15 , 59 );
120
119
String exp = dur .toString ();
121
120
assertEquals ("Should deserialize to equal Duration ('" +exp +"')" , dur ,
122
- new ObjectMapper () .readValue (q (exp ), Duration .class ));
121
+ MAPPER .readValue (q (exp ), Duration .class ));
123
122
}
124
123
}
0 commit comments