58
58
import com .fasterxml .jackson .datatype .joda .cfg .JacksonJodaDateFormat ;
59
59
import com .fasterxml .jackson .datatype .joda .ser .DateTimeSerializer ;
60
60
import org .joda .time .DateTime ;
61
+ import org .joda .time .DateTimeZone ;
61
62
import org .joda .time .format .DateTimeFormat ;
62
63
import org .junit .Test ;
63
64
@@ -223,16 +224,17 @@ public void setModules() {
223
224
@ Test
224
225
public void defaultModules () throws JsonProcessingException , UnsupportedEncodingException {
225
226
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder .json ().build ();
226
- DateTime dateTime = DateTime .parse ("2011-12-03T10:15:30" );
227
- assertEquals ("1322903730000" , new String (objectMapper .writeValueAsBytes (dateTime ), "UTF-8" ));
227
+ Long timestamp = 1322903730000L ;
228
+ DateTime dateTime = new DateTime (timestamp , DateTimeZone .UTC );
229
+ assertEquals (timestamp .toString (), new String (objectMapper .writeValueAsBytes (dateTime ), "UTF-8" ));
228
230
}
229
231
230
232
@ Test // SPR-12634
231
233
public void customizeDefaultModules () throws JsonProcessingException , UnsupportedEncodingException {
232
234
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder .json ()
233
235
.featuresToDisable (SerializationFeature .WRITE_DATES_AS_TIMESTAMPS )
234
236
.modulesToInstall (CustomModule .class ).build ();
235
- DateTime dateTime = DateTime . parse ( "2011-12-03T10:15:30" );
237
+ DateTime dateTime = new DateTime ( 1322903730000L , DateTimeZone . UTC );
236
238
assertEquals ("\" 2011-12-03\" " , new String (objectMapper .writeValueAsBytes (dateTime ), "UTF-8" ));
237
239
}
238
240
@@ -241,7 +243,7 @@ public void customizeDefaultModulesWithSerializer() throws JsonProcessingExcepti
241
243
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder .json ()
242
244
.serializerByType (DateTime .class , new DateTimeSerializer (new JacksonJodaDateFormat (DateTimeFormat .forPattern ("YYYY-MM-dd" ).withZoneUTC ())))
243
245
.featuresToDisable (SerializationFeature .WRITE_DATES_AS_TIMESTAMPS ).build ();
244
- DateTime dateTime = DateTime . parse ( "2011-12-03T10:15:30" );
246
+ DateTime dateTime = new DateTime ( 1322903730000L , DateTimeZone . UTC );
245
247
assertEquals ("\" 2011-12-03\" " , new String (objectMapper .writeValueAsBytes (dateTime ), "UTF-8" ));
246
248
}
247
249
0 commit comments