@@ -305,12 +305,10 @@ public void testDeserializationAsInt03MillisecondsWithTimeZone() throws Exceptio
305
305
public void testDeserializationAsString01WithoutTimeZone () throws Exception
306
306
{
307
307
OffsetDateTime date = OffsetDateTime .ofInstant (Instant .ofEpochSecond (0L ), Z1 );
308
+ ObjectReader r = MAPPER .readerFor (OffsetDateTime .class )
309
+ .with (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE );
310
+ OffsetDateTime value = r .readValue ('"' + FORMATTER .format (date ) + '"' );
308
311
309
- ObjectMapper m = newMapper ()
310
- .configure (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE , true );
311
- OffsetDateTime value = m .readValue ('"' + FORMATTER .format (date ) + '"' , OffsetDateTime .class );
312
-
313
- assertNotNull ("The value should not be null." , value );
314
312
assertIsEqual (date , value );
315
313
assertEquals ("The time zone is not correct." , ZoneOffset .UTC , value .getOffset ());
316
314
}
@@ -319,12 +317,11 @@ public void testDeserializationAsString01WithoutTimeZone() throws Exception
319
317
public void testDeserializationAsString01WithTimeZone () throws Exception
320
318
{
321
319
OffsetDateTime date = OffsetDateTime .ofInstant (Instant .ofEpochSecond (0L ), Z1 );
322
- ObjectMapper m = newMapper ( )
323
- . configure (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE , true )
324
- . setTimeZone (TimeZone .getDefault ());
325
- OffsetDateTime value = m .readValue ('"' + FORMATTER .format (date ) + '"' , OffsetDateTime . class );
320
+ ObjectReader r = MAPPER . readerFor ( OffsetDateTime . class )
321
+ . with (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE )
322
+ . with (TimeZone .getDefault ());
323
+ OffsetDateTime value = r .readValue ('"' + FORMATTER .format (date ) + '"' );
326
324
327
- assertNotNull ("The value should not be null." , value );
328
325
assertIsEqual (date , value );
329
326
assertEquals ("The time zone is not correct." , getDefaultOffset (date ), value .getOffset ());
330
327
}
@@ -333,12 +330,11 @@ public void testDeserializationAsString01WithTimeZone() throws Exception
333
330
public void testDeserializationAsString01WithTimeZoneTurnedOff () throws Exception
334
331
{
335
332
OffsetDateTime date = OffsetDateTime .ofInstant (Instant .ofEpochSecond (0L ), Z1 );
336
- ObjectMapper m = newMapper ( )
337
- . configure (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE , false )
338
- . setTimeZone (TimeZone .getDefault ());
339
- OffsetDateTime value = m .readValue ('"' + FORMATTER .format (date ) + '"' , OffsetDateTime . class );
333
+ ObjectReader r = MAPPER . readerFor ( OffsetDateTime . class )
334
+ . without (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE )
335
+ . with (TimeZone .getDefault ());
336
+ OffsetDateTime value = r .readValue ('"' + FORMATTER .format (date ) + '"' );
340
337
341
- assertNotNull ("The value should not be null." , value );
342
338
assertIsEqual (date , value );
343
339
assertEquals ("The time zone is not correct." , getOffset (value , Z1 ), value .getOffset ());
344
340
}
@@ -347,14 +343,12 @@ public void testDeserializationAsString01WithTimeZoneTurnedOff() throws Exceptio
347
343
public void testDeserializationAsString01WithTimeZoneColonless () throws Exception
348
344
{
349
345
OffsetDateTime date = OffsetDateTime .ofInstant (Instant .ofEpochSecond (0L ), Z1 );
350
- ObjectMapper m = newMapper ( )
351
- . configure (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE , false );
346
+ ObjectReader r = MAPPER . readerFor ( OffsetDateTime . class )
347
+ . without (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE );
352
348
353
349
String sDate = offsetWithoutColon (FORMATTER .format (date ));
350
+ OffsetDateTime value = r .readValue ('"' + sDate + '"' );
354
351
355
- OffsetDateTime value = m .readValue ('"' + sDate + '"' , OffsetDateTime .class );
356
-
357
- assertNotNull ("The value should not be null." , value );
358
352
assertIsEqual (date , value );
359
353
assertEquals ("The time zone is not correct." , getOffset (value , Z1 ), value .getOffset ());
360
354
}
@@ -363,11 +357,10 @@ public void testDeserializationAsString01WithTimeZoneColonless() throws Exceptio
363
357
public void testDeserializationAsString02WithoutTimeZone () throws Exception
364
358
{
365
359
OffsetDateTime date = OffsetDateTime .ofInstant (Instant .ofEpochSecond (123456789L , 183917322 ), Z2 );
366
- ObjectMapper m = newMapper ( )
367
- .configure (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE , true );
368
- OffsetDateTime value = m .readValue ('"' + FORMATTER .format (date ) + '"' , OffsetDateTime . class );
360
+ ObjectReader r = MAPPER . readerFor ( OffsetDateTime . class )
361
+ .with (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE );
362
+ OffsetDateTime value = r .readValue ('"' + FORMATTER .format (date ) + '"' );
369
363
370
- assertNotNull ("The value should not be null." , value );
371
364
assertIsEqual (date , value );
372
365
assertEquals ("The time zone is not correct." , ZoneOffset .UTC , value .getOffset ());
373
366
}
@@ -376,12 +369,11 @@ public void testDeserializationAsString02WithoutTimeZone() throws Exception
376
369
public void testDeserializationAsString02WithTimeZone () throws Exception
377
370
{
378
371
OffsetDateTime date = OffsetDateTime .ofInstant (Instant .ofEpochSecond (123456789L , 183917322 ), Z2 );
379
- ObjectMapper m = newMapper ( )
380
- . configure (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE , true )
381
- . setTimeZone (TimeZone .getDefault ());
382
- OffsetDateTime value = m .readValue ('"' + FORMATTER .format (date ) + '"' , OffsetDateTime . class );
372
+ ObjectReader r = MAPPER . readerFor ( OffsetDateTime . class )
373
+ . with (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE )
374
+ . with (TimeZone .getDefault ());
375
+ OffsetDateTime value = r .readValue ('"' + FORMATTER .format (date ) + '"' );
383
376
384
- assertNotNull ("The value should not be null." , value );
385
377
assertIsEqual (date , value );
386
378
assertEquals ("The time zone is not correct." , getDefaultOffset (date ), value .getOffset ());
387
379
}
@@ -420,11 +412,10 @@ public void testDeserializationAsString02WithTimeZoneColonless() throws Exceptio
420
412
public void testDeserializationAsString03WithoutTimeZone () throws Exception
421
413
{
422
414
OffsetDateTime date = OffsetDateTime .now (Z3 );
423
- ObjectMapper m = newMapper ( )
424
- .configure (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE , true );
425
- OffsetDateTime value = m .readValue ('"' + FORMATTER .format (date ) + '"' , OffsetDateTime . class );
415
+ ObjectReader r = MAPPER . readerFor ( OffsetDateTime . class )
416
+ .with (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE );
417
+ OffsetDateTime value = r .readValue ('"' + FORMATTER .format (date ) + '"' );
426
418
427
- assertNotNull ("The value should not be null." , value );
428
419
assertIsEqual (date , value );
429
420
assertEquals ("The time zone is not correct." , ZoneOffset .UTC , value .getOffset ());
430
421
}
@@ -433,12 +424,11 @@ public void testDeserializationAsString03WithoutTimeZone() throws Exception
433
424
public void testDeserializationAsString03WithTimeZone () throws Exception
434
425
{
435
426
OffsetDateTime date = OffsetDateTime .now (Z3 );
436
- ObjectMapper m = newMapper ( )
437
- . configure (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE , true )
438
- . setTimeZone (TimeZone .getDefault ());
439
- OffsetDateTime value = m .readValue ('"' + FORMATTER .format (date ) + '"' , OffsetDateTime . class );
427
+ ObjectReader r = MAPPER . readerFor ( OffsetDateTime . class )
428
+ . with (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE )
429
+ . with (TimeZone .getDefault ());
430
+ OffsetDateTime value = r .readValue ('"' + FORMATTER .format (date ) + '"' );
440
431
441
- assertNotNull ("The value should not be null." , value );
442
432
assertIsEqual (date , value );
443
433
assertEquals ("The time zone is not correct." , getDefaultOffset (date ), value .getOffset ());
444
434
}
@@ -447,12 +437,11 @@ public void testDeserializationAsString03WithTimeZone() throws Exception
447
437
public void testDeserializationAsString03WithTimeZoneTurnedOff () throws Exception
448
438
{
449
439
OffsetDateTime date = OffsetDateTime .now (Z3 );
450
- ObjectMapper m = newMapper ( )
451
- . configure (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE , false )
452
- . setTimeZone (TimeZone .getDefault ());
453
- OffsetDateTime value = m .readValue ('"' + FORMATTER .format (date ) + '"' , OffsetDateTime . class );
440
+ ObjectReader r = MAPPER . readerFor ( OffsetDateTime . class )
441
+ . without (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE )
442
+ . with (TimeZone .getDefault ());
443
+ OffsetDateTime value = r .readValue ('"' + FORMATTER .format (date ) + '"' );
454
444
455
- assertNotNull ("The value should not be null." , value );
456
445
assertIsEqual (date , value );
457
446
assertEquals ("The time zone is not correct." , getOffset (value , Z3 ), value .getOffset ());
458
447
}
@@ -462,14 +451,12 @@ public void testDeserializationAsString03WithTimeZoneTurnedOff() throws Exceptio
462
451
public void testDeserializationAsString03WithTimeZoneColonless () throws Exception
463
452
{
464
453
OffsetDateTime date = OffsetDateTime .now (Z3 );
465
- ObjectMapper m = newMapper ()
466
- .configure (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE , false );
467
-
454
+ ObjectReader r = MAPPER .readerFor (OffsetDateTime .class )
455
+ .without (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE );
468
456
String sDate = offsetWithoutColon (FORMATTER .format (date ));
469
457
470
- OffsetDateTime value = m .readValue ('"' + sDate + '"' , OffsetDateTime . class );
458
+ OffsetDateTime value = r .readValue ('"' + sDate + '"' );
471
459
472
- assertNotNull ("The value should not be null." , value );
473
460
assertIsEqual (date , value );
474
461
assertEquals ("The time zone is not correct." , getOffset (value , Z3 ), value .getOffset ());
475
462
}
@@ -484,7 +471,6 @@ public void testDeserializationWithTypeInfo01WithoutTimeZone() throws Exception
484
471
"[\" " + OffsetDateTime .class .getName () + "\" ,123456789.183917322]" , Temporal .class
485
472
);
486
473
487
- assertNotNull ("The value should not be null." , value );
488
474
assertTrue ("The value should be an OffsetDateTime." , value instanceof OffsetDateTime );
489
475
assertIsEqual (date , (OffsetDateTime ) value );
490
476
assertEquals ("The time zone is not correct." , ZoneOffset .UTC , ((OffsetDateTime ) value ).getOffset ());
@@ -501,7 +487,6 @@ public void testDeserializationWithTypeInfo01WithTimeZone() throws Exception
501
487
"[\" " + OffsetDateTime .class .getName () + "\" ,123456789.183917322]" , Temporal .class
502
488
);
503
489
504
- assertNotNull ("The value should not be null." , value );
505
490
assertTrue ("The value should be an OffsetDateTime." , value instanceof OffsetDateTime );
506
491
assertIsEqual (date , (OffsetDateTime ) value );
507
492
assertEquals ("The time zone is not correct." , getDefaultOffset (date ), ((OffsetDateTime ) value ).getOffset ());
@@ -518,7 +503,6 @@ public void testDeserializationWithTypeInfo02WithoutTimeZone() throws Exception
518
503
"[\" " + OffsetDateTime .class .getName () + "\" ,123456789]" , Temporal .class
519
504
);
520
505
521
- assertNotNull ("The value should not be null." , value );
522
506
assertTrue ("The value should be an OffsetDateTime." , value instanceof OffsetDateTime );
523
507
assertIsEqual (date , (OffsetDateTime ) value );
524
508
assertEquals ("The time zone is not correct." , ZoneOffset .UTC , ((OffsetDateTime ) value ).getOffset ());
@@ -536,7 +520,6 @@ public void testDeserializationWithTypeInfo02WithTimeZone() throws Exception
536
520
"[\" " + OffsetDateTime .class .getName () + "\" ,123456789]" , Temporal .class
537
521
);
538
522
539
- assertNotNull ("The value should not be null." , value );
540
523
assertTrue ("The value should be an OffsetDateTime." , value instanceof OffsetDateTime );
541
524
assertIsEqual (date , (OffsetDateTime ) value );
542
525
assertEquals ("The time zone is not correct." , getDefaultOffset (date ), ((OffsetDateTime ) value ).getOffset ());
@@ -553,7 +536,6 @@ public void testDeserializationWithTypeInfo03WithoutTimeZone() throws Exception
553
536
"[\" " + OffsetDateTime .class .getName () + "\" ,123456789422]" , Temporal .class
554
537
);
555
538
556
- assertNotNull ("The value should not be null." , value );
557
539
assertTrue ("The value should be an OffsetDateTime." , value instanceof OffsetDateTime );
558
540
assertIsEqual (date , (OffsetDateTime ) value );
559
541
assertEquals ("The time zone is not correct." , ZoneOffset .UTC , ((OffsetDateTime ) value ).getOffset ());
@@ -571,7 +553,6 @@ public void testDeserializationWithTypeInfo03WithTimeZone() throws Exception
571
553
"[\" " + OffsetDateTime .class .getName () + "\" ,123456789422]" , Temporal .class
572
554
);
573
555
574
- assertNotNull ("The value should not be null." , value );
575
556
assertTrue ("The value should be an OffsetDateTime." , value instanceof OffsetDateTime );
576
557
assertIsEqual (date , (OffsetDateTime ) value );
577
558
assertEquals ("The time zone is not correct." , getDefaultOffset (date ), ((OffsetDateTime ) value ).getOffset ());
@@ -588,7 +569,6 @@ public void testDeserializationWithTypeInfo04WithoutTimeZone() throws Exception
588
569
"[\" " + OffsetDateTime .class .getName () + "\" ,\" " + FORMATTER .format (date ) + "\" ]" , Temporal .class
589
570
);
590
571
591
- assertNotNull ("The value should not be null." , value );
592
572
assertTrue ("The value should be an OffsetDateTime." , value instanceof OffsetDateTime );
593
573
assertIsEqual (date , (OffsetDateTime ) value );
594
574
assertEquals ("The time zone is not correct." , ZoneOffset .UTC , ((OffsetDateTime ) value ).getOffset ());
@@ -606,7 +586,6 @@ public void testDeserializationWithTypeInfo04WithTimeZone() throws Exception
606
586
"[\" " + OffsetDateTime .class .getName () + "\" ,\" " + FORMATTER .format (date ) + "\" ]" , Temporal .class
607
587
);
608
588
609
- assertNotNull ("The value should not be null." , value );
610
589
assertTrue ("The value should be an OffsetDateTime." , value instanceof OffsetDateTime );
611
590
assertIsEqual (date , (OffsetDateTime ) value );
612
591
assertEquals ("The time zone is not correct." , getDefaultOffset (date ), ((OffsetDateTime ) value ).getOffset ());
@@ -625,7 +604,6 @@ public void testDeserializationWithTypeInfo04WithTimeZoneTurnedOff() throws Exce
625
604
"[\" " + OffsetDateTime .class .getName () + "\" ,\" " + FORMATTER .format (date ) + "\" ]" , Temporal .class
626
605
);
627
606
628
- assertNotNull ("The value should not be null." , value );
629
607
assertTrue ("The value should be an OffsetDateTime." , value instanceof OffsetDateTime );
630
608
OffsetDateTime cast = (OffsetDateTime ) value ;
631
609
assertIsEqual (date , cast );
0 commit comments