@@ -522,6 +522,79 @@ public void testRoundTripOfOffsetDateTimeAndJavaUtilDate() throws Exception
522
522
assertEquals (givenInstant .atOffset (ZoneOffset .UTC ), actual );
523
523
}
524
524
525
+ /*
526
+ * Tests for the deserialization of OffsetDateTimes that cannot be
527
+ * normalized with ADJUST_DATES_TO_CONTEXT_TIME_ZONE enabled. The expected
528
+ * behaviour is that normalization is skipped for those OffsetDateTimes
529
+ * that cannot be normalized. See [jackson-modules-java8#166].
530
+ */
531
+
532
+ @ Test
533
+ public void testDeserializationOfOffsetDateTimeMin () throws Exception
534
+ {
535
+ OffsetDateTime date = OffsetDateTime .MIN ;
536
+ OffsetDateTime value = MAPPER .readerFor (OffsetDateTime .class )
537
+ .with (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE )
538
+ .readValue ('"' + FORMATTER .format (date ) + '"' );
539
+ assertIsEqual (date , value );
540
+ assertNotEquals ("The time zone has been normalized." , ZoneOffset .UTC , value .getOffset ());
541
+ }
542
+
543
+ @ Test
544
+ public void testDeserializationOfUnadjustableOffsetDateTimeNearMin () throws Exception
545
+ {
546
+ OffsetDateTime date = OffsetDateTime .MIN .plusHours (18 ).minusNanos (1 );
547
+ OffsetDateTime value = MAPPER .readerFor (OffsetDateTime .class )
548
+ .with (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE )
549
+ .readValue ('"' + FORMATTER .format (date ) + '"' );
550
+ assertIsEqual (date , value );
551
+ assertNotEquals ("The time zone has been normalized." , ZoneOffset .UTC , value .getOffset ());
552
+ }
553
+
554
+ @ Test
555
+ public void testDeserializationOfAdjustableOffsetDateTimeNearMin () throws Exception
556
+ {
557
+ OffsetDateTime date = OffsetDateTime .MIN .plusHours (18 );
558
+ OffsetDateTime value = MAPPER .readerFor (OffsetDateTime .class )
559
+ .with (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE )
560
+ .readValue ('"' + FORMATTER .format (date ) + '"' );
561
+ assertIsEqual (date , value );
562
+ assertEquals ("The time zone is not correct." , ZoneOffset .UTC , value .getOffset ());
563
+ }
564
+
565
+ @ Test
566
+ public void testDeserializationOfOffsetDateTimeMax () throws Exception
567
+ {
568
+ OffsetDateTime date = OffsetDateTime .MAX ;
569
+ OffsetDateTime value = MAPPER .readerFor (OffsetDateTime .class )
570
+ .with (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE )
571
+ .readValue ('"' + FORMATTER .format (date ) + '"' );
572
+ assertIsEqual (date , value );
573
+ assertNotEquals ("The time zone has been normalized." , ZoneOffset .UTC , value .getOffset ());
574
+ }
575
+
576
+ @ Test
577
+ public void testDeserializationOfUnadjustableOffsetDateTimeNearMax () throws Exception
578
+ {
579
+ OffsetDateTime date = OffsetDateTime .MAX .minusHours (18 ).plusNanos (1 );
580
+ OffsetDateTime value = MAPPER .readerFor (OffsetDateTime .class )
581
+ .with (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE )
582
+ .readValue ('"' + FORMATTER .format (date ) + '"' );
583
+ assertIsEqual (date , value );
584
+ assertNotEquals ("The time zone has been normalized." , ZoneOffset .UTC , value .getOffset ());
585
+ }
586
+
587
+ @ Test
588
+ public void testDeserializationOfAdjustableOffsetDateTimeNearMax () throws Exception
589
+ {
590
+ OffsetDateTime date = OffsetDateTime .MAX .minusHours (18 );
591
+ OffsetDateTime value = MAPPER .readerFor (OffsetDateTime .class )
592
+ .with (DeserializationFeature .ADJUST_DATES_TO_CONTEXT_TIME_ZONE )
593
+ .readValue ('"' + FORMATTER .format (date ) + '"' );
594
+ assertIsEqual (date , value );
595
+ assertEquals ("The time zone is not correct." , ZoneOffset .UTC , value .getOffset ());
596
+ }
597
+
525
598
/*
526
599
/**********************************************************
527
600
/* Tests for empty string handling
0 commit comments