@@ -67,6 +67,24 @@ public class InstantDeserializer<T extends Temporal>
6767 */
6868 protected static final Pattern ISO8601_COLONLESS_OFFSET_REGEX = Pattern .compile ("[+-][0-9]{4}(?=\\ [|$)" );
6969
70+ /**
71+ *
72+ * @param args
73+ * @return
74+ */
75+ private static OffsetDateTime decimalToOffsetDateTime (FromDecimalArguments args ) {
76+ // [jackson-modules-java8#308] Fix can't deserialize OffsetDateTime.MIN: Invalid value for EpochDay
77+ if (args .integer == OffsetDateTime .MIN .toEpochSecond () && args .fraction == OffsetDateTime .MIN .getNano ()) {
78+ return OffsetDateTime .ofInstant (Instant .ofEpochSecond (OffsetDateTime .MIN .toEpochSecond (), OffsetDateTime .MIN .getNano ()), OffsetDateTime .MIN .getOffset ());
79+ }
80+ // [jackson-modules-java8#308] For OffsetDateTime.MAX case
81+ if (args .integer == OffsetDateTime .MAX .toEpochSecond () && args .fraction == OffsetDateTime .MAX .getNano ()) {
82+ return OffsetDateTime .ofInstant (Instant .ofEpochSecond (OffsetDateTime .MAX .toEpochSecond (), OffsetDateTime .MAX .getNano ()), OffsetDateTime .MAX .getOffset ());
83+ }
84+ return OffsetDateTime .ofInstant (Instant .ofEpochSecond (args .integer , args .fraction ), args .zoneId );
85+ }
86+
87+
7088 public static final InstantDeserializer <Instant > INSTANT = new InstantDeserializer <>(
7189 Instant .class , DateTimeFormatter .ISO_INSTANT ,
7290 Instant ::from ,
@@ -82,7 +100,7 @@ public class InstantDeserializer<T extends Temporal>
82100 OffsetDateTime .class , DateTimeFormatter .ISO_OFFSET_DATE_TIME ,
83101 OffsetDateTime ::from ,
84102 a -> OffsetDateTime .ofInstant (Instant .ofEpochMilli (a .value ), a .zoneId ),
85- a -> OffsetDateTime . ofInstant ( Instant . ofEpochSecond ( a . integer , a . fraction ), a . zoneId ) ,
103+ InstantDeserializer :: decimalToOffsetDateTime ,
86104 (d , z ) -> (d .isEqual (OffsetDateTime .MIN ) || d .isEqual (OffsetDateTime .MAX ) ? d : d .withOffsetSameInstant (z .getRules ().getOffset (d .toLocalDateTime ()))),
87105 true , // yes, replace zero offset with Z
88106 DEFAULT_NORMALIZE_ZONE_ID ,
@@ -542,5 +560,16 @@ public static class FromDecimalArguments // since 2.8.3
542560 this .fraction = fraction ;
543561 this .zoneId = zoneId ;
544562 }
563+
564+ public static boolean matches (FromDecimalArguments a , FromDecimalArguments b ) {
565+ if (a == b ) {
566+ return true ;
567+ }
568+ if (a == null || b == null ) {
569+ return false ;
570+ }
571+ return a .integer == b .integer && a .fraction == b .fraction
572+ && a .zoneId .equals (b .zoneId );
573+ }
545574 }
546575}
0 commit comments