Skip to content

Commit

Permalink
Merge branch '2.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 5, 2019
2 parents 3e051be + 54010cf commit 08b9106
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.fasterxml.jackson.datatype.jsr310.deser.key;

import static java.time.temporal.ChronoField.YEAR;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.Year;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.SignStyle;

import com.fasterxml.jackson.databind.DeserializationContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,35 @@ public class YearAsKeyTest extends ModuleTestBase
private final ObjectReader READER = MAPPER.readerFor(TYPE_REF);

@Test
public void testSerialization() throws Exception {
public void testKeySerialization() throws Exception {
assertEquals("Value is incorrect", mapAsString("3141", "test"),
MAPPER.writeValueAsString(asMap(Year.of(3141), "test")));
}

@Test
public void testDeserialization() throws Exception {
public void testKeyDeserialization() throws Exception {
assertEquals("Value is incorrect", asMap(Year.of(3141), "test"),
READER.readValue(mapAsString("3141", "test")));
// Test both padded, unpadded
assertEquals("Value is incorrect", asMap(Year.of(476), "test"),
READER.readValue(mapAsString("0476", "test")));
assertEquals("Value is incorrect", asMap(Year.of(476), "test"),
READER.readValue(mapAsString("476", "test")));
}

@Test
public void serializeAndDeserializeYearKeyUnpadded() throws Exception {
// fix for issue #51 verify we can deserialize an unpadded year e.g. "1"
Map<Year, Float> testMap = Collections.singletonMap(Year.of(1), 1F);
String serialized = MAPPER.writeValueAsString(testMap);
TypeReference<Map<Year, Float>> yearFloatTypeReference = new TypeReference<Map<Year, Float>>() {};
Map<Year, Float> deserialized = MAPPER.readValue(serialized, yearFloatTypeReference);
assertEquals(testMap, deserialized);

// actually, check padded as well just to make sure
Map<Year, Float> deserialized2 = MAPPER.readValue(aposToQuotes("{'0001':1.0}"),
yearFloatTypeReference);
assertEquals(testMap, deserialized2);
}

@Test(expected = InvalidFormatException.class)
Expand All @@ -41,15 +61,4 @@ public void deserializeYearKey_notANumber() throws Exception {
public void deserializeYearKey_notAYear() throws Exception {
READER.readValue(mapAsString(Integer.toString(Year.MAX_VALUE+1), "test"));
}

@Test
public void serializeAndDeserializeYearKeyUnpadded() throws Exception {
// fix for issue #51 verify we can deserialize an unpadded year e.g. "1"
ObjectMapper unpaddedMapper = newMapper();
Map<Year, Float> testMap = Collections.singletonMap(Year.of(1), 1F);
String serialized = unpaddedMapper.writeValueAsString(testMap);
TypeReference<Map<Year, Float>> yearFloatTypeReference = new TypeReference<Map<Year, Float>>() {};
Map<Year, Float> deserialized = unpaddedMapper.readValue(serialized, yearFloatTypeReference);
assertEquals(testMap, deserialized);
}
}
3 changes: 3 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ Michael O'Keeffe (kupci@github)
* Contributed fix for #69: `ZonedDateTime` for times before the epoch do not
serialize correctly
(2.10.0)
* Contributed fix for #51: `YearKeyDeserializer` doesn't work with non-padded
year values
(2.10.0)
7 changes: 6 additions & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ Modules:
=== Releases ===
------------------------------------------------------------------------

2.10.0.pr2
2.10.0 (not yet released)

#51: `YearKeyDeserializer` doesn't work with non-padded year values
(reported by sladkoff@github; fix contributed by Mike [kupci@github])
2.10.0.pr2 (31-Aug-2019)
#69: `ZonedDateTime` for times before the epoch do not serialize correctly
(fixed by Mike [kupci@github])
Expand Down

0 comments on commit 08b9106

Please sign in to comment.