|
1 | 1 | package com.fasterxml.jackson.datatype.threetenbp.deser;
|
2 | 2 |
|
| 3 | +import org.junit.Ignore; |
3 | 4 | import org.threeten.bp.*;
|
4 | 5 | import org.threeten.bp.format.DateTimeFormatter;
|
5 | 6 | import org.threeten.bp.temporal.ChronoUnit;
|
|
23 | 24 | import static com.fasterxml.jackson.datatype.threetenbp.deser.InstantDeserializer.ISO8601_COLONLESS_OFFSET_REGEX;
|
24 | 25 | import static org.junit.Assert.*;
|
25 | 26 | import static org.junit.Assert.assertNull;
|
| 27 | +import static org.junit.Assume.assumeTrue; |
26 | 28 |
|
27 | 29 | public class InstantDeserTest extends ModuleTestBase
|
28 | 30 | {
|
@@ -388,9 +390,9 @@ public void testCustomPatternWithAnnotations02() throws Exception
|
388 | 390 | {
|
389 | 391 | //Test date is pushed one year after start of the epoch just to avoid possible issues with UTC-X TZs which could
|
390 | 392 | //push the instant before tha start of the epoch
|
391 |
| - final Instant instant = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0), ZoneId.of("UTC")).plusYears(1).toInstant(); |
| 393 | + final Instant instant = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0), ZoneOffset.UTC).plusYears(1).toInstant(); |
392 | 394 | final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(CUSTOM_PATTERN);
|
393 |
| - final String valueInUTC = formatter.withZone(ZoneId.of("UTC")).format(instant); |
| 395 | + final String valueInUTC = formatter.withZone(ZoneOffset.UTC).format(instant); |
394 | 396 |
|
395 | 397 | final WrapperWithCustomPattern input = new WrapperWithCustomPattern(instant);
|
396 | 398 | String json = MAPPER.writeValueAsString(input);
|
@@ -434,10 +436,46 @@ public void testDeserializationFromStringWithZeroZoneOffset03() throws Exception
|
434 | 436 | assertEquals("The value is not correct.", date, result);
|
435 | 437 | }
|
436 | 438 |
|
| 439 | + @Test |
| 440 | + @Ignore("Currently not implemented in ThreeTenBP - https://bugs.openjdk.org/browse/JDK-8166138") |
| 441 | + public void testDeserializationFromStringWithZeroZoneOffset04() throws Exception { |
| 442 | + assumeInstantCanParseOffsets(); |
| 443 | + Instant date = Instant.now(); |
| 444 | + String json = formatWithZeroZoneOffset(date, "+00:30"); |
| 445 | + Instant result = READER.readValue(json); |
| 446 | + assertNotEquals("The value is not correct.", date, result); |
| 447 | + } |
| 448 | + |
| 449 | + @Test |
| 450 | + @Ignore("Currently not implemented in ThreeTenBP - https://bugs.openjdk.org/browse/JDK-8166138") |
| 451 | + public void testDeserializationFromStringWithZeroZoneOffset05() throws Exception { |
| 452 | + assumeInstantCanParseOffsets(); |
| 453 | + Instant date = Instant.now(); |
| 454 | + String json = formatWithZeroZoneOffset(date, "+01:30"); |
| 455 | + Instant result = READER.readValue(json); |
| 456 | + assertNotEquals("The value is not correct.", date, result); |
| 457 | + } |
| 458 | + |
| 459 | + @Test |
| 460 | + @Ignore("Currently not implemented in ThreeTenBP - https://bugs.openjdk.org/browse/JDK-8166138") |
| 461 | + public void testDeserializationFromStringWithZeroZoneOffset06() throws Exception { |
| 462 | + assumeInstantCanParseOffsets(); |
| 463 | + Instant date = Instant.now(); |
| 464 | + String json = formatWithZeroZoneOffset(date, "-00:00"); |
| 465 | + Instant result = READER.readValue(json); |
| 466 | + assertEquals("The value is not correct.", date, result); |
| 467 | + } |
| 468 | + |
437 | 469 | private String formatWithZeroZoneOffset(Instant date, String offset){
|
438 | 470 | return '"' + FORMATTER.format(date).replaceFirst("Z$", offset) + '"';
|
439 | 471 | }
|
440 | 472 |
|
| 473 | + private static void assumeInstantCanParseOffsets() { |
| 474 | + // DateTimeFormatter.ISO_INSTANT didn't handle offsets until JDK 12+. |
| 475 | + // This was added by https://bugs.openjdk.org/browse/JDK-8166138 |
| 476 | + assumeTrue(System.getProperty("java.specification.version").compareTo("12") > 0); |
| 477 | + } |
| 478 | + |
441 | 479 | /*
|
442 | 480 | /**********************************************************************
|
443 | 481 | /* Deserialization, misc other
|
|
0 commit comments