-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...c/test/java/tools/jackson/datatype/jsr310/deser/key/ZonedDateTimeKeyDeserializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package tools.jackson.datatype.jsr310.deser.key; | ||
|
||
import org.junit.Test; | ||
|
||
import tools.jackson.core.type.TypeReference; | ||
|
||
import tools.jackson.databind.ObjectMapper; | ||
import tools.jackson.datatype.jsr310.ModuleTestBase; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assume.*; | ||
|
||
// for [modules-java8#306] | ||
public class ZonedDateTimeKeyDeserializerTest | ||
extends ModuleTestBase | ||
{ | ||
private final ObjectMapper MAPPER = newMapper(); | ||
private final TypeReference<Map<ZonedDateTime, String>> MAP_TYPE_REF | ||
= new TypeReference<Map<ZonedDateTime, String>>() {}; | ||
|
||
@Test | ||
public void Instant_style_can_be_deserialized() throws Exception { | ||
Map<ZonedDateTime, String> map = MAPPER.readValue(getMap("2015-07-24T12:23:34.184Z"), | ||
MAP_TYPE_REF); | ||
Map.Entry<ZonedDateTime, String> entry = map.entrySet().iterator().next(); | ||
assertEquals("2015-07-24T12:23:34.184Z", entry.getKey().toString()); | ||
} | ||
|
||
@Test | ||
public void ZonedDateTime_with_zone_name_can_be_deserialized() throws Exception { | ||
Map<ZonedDateTime, String> map = MAPPER.readValue(getMap("2015-07-24T12:23:34.184Z[UTC]"), | ||
MAP_TYPE_REF); | ||
Map.Entry<ZonedDateTime, String> entry = map.entrySet().iterator().next(); | ||
assertEquals("2015-07-24T12:23:34.184Z[UTC]", entry.getKey().toString()); | ||
} | ||
|
||
@Test | ||
public void ZonedDateTime_with_place_name_can_be_deserialized() throws Exception { | ||
assumeFalse(System.getProperty("java.version").startsWith("1.8")); | ||
|
||
Map<ZonedDateTime, String> map = MAPPER.readValue(getMap("2015-07-24T12:23:34.184Z[Europe/London]"), | ||
MAP_TYPE_REF); | ||
Map.Entry<ZonedDateTime, String> entry = map.entrySet().iterator().next(); | ||
assertEquals("2015-07-24T13:23:34.184+01:00[Europe/London]", entry.getKey().toString()); | ||
} | ||
|
||
@Test | ||
public void ZonedDateTime_with_place_name_can_be_deserialized_Java_8() throws Exception { | ||
// Java 8 parses this format incorrectly due to https://bugs.openjdk.org/browse/JDK-8066982 | ||
assumeTrue(System.getProperty("java.version").startsWith("1.8")); | ||
|
||
Map<ZonedDateTime, String> map = MAPPER.readValue(getMap("2015-07-24T12:23:34.184Z[Europe/London]"), | ||
MAP_TYPE_REF); | ||
Map.Entry<ZonedDateTime, String> entry = map.entrySet().iterator().next(); | ||
assertEquals("2015-07-24T12:23:34.184+01:00[Europe/London]", entry.getKey().toString()); | ||
} | ||
|
||
@Test | ||
public void ZonedDateTime_with_offset_can_be_deserialized() throws Exception { | ||
Map<ZonedDateTime, String> map = MAPPER.readValue(getMap("2015-07-24T12:23:34.184+02:00"), | ||
MAP_TYPE_REF); | ||
Map.Entry<ZonedDateTime, String> entry = map.entrySet().iterator().next(); | ||
assertEquals("2015-07-24T12:23:34.184+02:00", entry.getKey().toString()); | ||
} | ||
|
||
private static String getMap(String input) { | ||
return "{\"" + input + "\": \"This is a string\"}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters