File tree Expand file tree Collapse file tree 1 file changed +20
-8
lines changed
datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser Expand file tree Collapse file tree 1 file changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -54,13 +54,6 @@ public class InstantDeserializer<T extends Temporal>
54
54
{
55
55
private static final long serialVersionUID = 1L ;
56
56
57
- /**
58
- * Constants used to check if the time offset is zero. See [jackson-modules-java8#18]
59
- *
60
- * @since 2.9.0
61
- */
62
- private static final Pattern ISO8601_UTC_ZERO_OFFSET_SUFFIX_REGEX = Pattern .compile ("\\ +00:?(00)?$" );
63
-
64
57
/**
65
58
* Constants used to check if ISO 8601 time string is colonless. See [jackson-modules-java8#131]
66
59
*
@@ -337,12 +330,31 @@ private ZoneId getZone(DeserializationContext context)
337
330
private String replaceZeroOffsetAsZIfNecessary (String text )
338
331
{
339
332
if (replaceZeroOffsetAsZ ) {
340
- return ISO8601_UTC_ZERO_OFFSET_SUFFIX_REGEX . matcher (text ). replaceFirst ( "Z" );
333
+ return replaceZeroOffsetAsZ (text );
341
334
}
342
335
343
336
return text ;
344
337
}
345
338
339
+ private static String replaceZeroOffsetAsZ (String text )
340
+ {
341
+ int plusIndex = text .lastIndexOf ('+' );
342
+ if (plusIndex < 0 ) {
343
+ return text ;
344
+ }
345
+ int maybeOffsetIndex = plusIndex + 1 ;
346
+ int remaining = text .length () - maybeOffsetIndex ;
347
+ if (remaining != 2 && remaining != 4 && remaining != 5 ) {
348
+ return text ;
349
+ }
350
+
351
+ String maybeOffset = text .substring (maybeOffsetIndex );
352
+ if ("00" .equals (maybeOffset ) || "00:00" .equals (maybeOffset ) || "0000" .equals (maybeOffset )) {
353
+ return text .substring (0 , plusIndex ) + 'Z' ;
354
+ }
355
+ return text ;
356
+ }
357
+
346
358
// @since 2.13
347
359
private String addInColonToOffsetIfMissing (String text )
348
360
{
You can’t perform that action at this time.
0 commit comments