Skip to content

Commit 08b9106

Browse files
committed
Merge branch '2.10'
2 parents 3e051be + 54010cf commit 08b9106

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/key/YearKeyDeserializer.java

-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package com.fasterxml.jackson.datatype.jsr310.deser.key;
22

3-
import static java.time.temporal.ChronoField.YEAR;
4-
53
import java.io.IOException;
64
import java.time.DateTimeException;
75
import java.time.Year;
8-
import java.time.format.DateTimeFormatter;
9-
import java.time.format.DateTimeFormatterBuilder;
10-
import java.time.format.SignStyle;
116

127
import com.fasterxml.jackson.databind.DeserializationContext;
138

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/key/YearAsKeyTest.java

+22-13
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,35 @@ public class YearAsKeyTest extends ModuleTestBase
2121
private final ObjectReader READER = MAPPER.readerFor(TYPE_REF);
2222

2323
@Test
24-
public void testSerialization() throws Exception {
24+
public void testKeySerialization() throws Exception {
2525
assertEquals("Value is incorrect", mapAsString("3141", "test"),
2626
MAPPER.writeValueAsString(asMap(Year.of(3141), "test")));
2727
}
2828

2929
@Test
30-
public void testDeserialization() throws Exception {
30+
public void testKeyDeserialization() throws Exception {
3131
assertEquals("Value is incorrect", asMap(Year.of(3141), "test"),
3232
READER.readValue(mapAsString("3141", "test")));
33+
// Test both padded, unpadded
34+
assertEquals("Value is incorrect", asMap(Year.of(476), "test"),
35+
READER.readValue(mapAsString("0476", "test")));
36+
assertEquals("Value is incorrect", asMap(Year.of(476), "test"),
37+
READER.readValue(mapAsString("476", "test")));
38+
}
39+
40+
@Test
41+
public void serializeAndDeserializeYearKeyUnpadded() throws Exception {
42+
// fix for issue #51 verify we can deserialize an unpadded year e.g. "1"
43+
Map<Year, Float> testMap = Collections.singletonMap(Year.of(1), 1F);
44+
String serialized = MAPPER.writeValueAsString(testMap);
45+
TypeReference<Map<Year, Float>> yearFloatTypeReference = new TypeReference<Map<Year, Float>>() {};
46+
Map<Year, Float> deserialized = MAPPER.readValue(serialized, yearFloatTypeReference);
47+
assertEquals(testMap, deserialized);
48+
49+
// actually, check padded as well just to make sure
50+
Map<Year, Float> deserialized2 = MAPPER.readValue(aposToQuotes("{'0001':1.0}"),
51+
yearFloatTypeReference);
52+
assertEquals(testMap, deserialized2);
3353
}
3454

3555
@Test(expected = InvalidFormatException.class)
@@ -41,15 +61,4 @@ public void deserializeYearKey_notANumber() throws Exception {
4161
public void deserializeYearKey_notAYear() throws Exception {
4262
READER.readValue(mapAsString(Integer.toString(Year.MAX_VALUE+1), "test"));
4363
}
44-
45-
@Test
46-
public void serializeAndDeserializeYearKeyUnpadded() throws Exception {
47-
// fix for issue #51 verify we can deserialize an unpadded year e.g. "1"
48-
ObjectMapper unpaddedMapper = newMapper();
49-
Map<Year, Float> testMap = Collections.singletonMap(Year.of(1), 1F);
50-
String serialized = unpaddedMapper.writeValueAsString(testMap);
51-
TypeReference<Map<Year, Float>> yearFloatTypeReference = new TypeReference<Map<Year, Float>>() {};
52-
Map<Year, Float> deserialized = unpaddedMapper.readValue(serialized, yearFloatTypeReference);
53-
assertEquals(testMap, deserialized);
54-
}
5564
}

release-notes/CREDITS-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ Michael O'Keeffe (kupci@github)
6262
* Contributed fix for #69: `ZonedDateTime` for times before the epoch do not
6363
serialize correctly
6464
(2.10.0)
65+
* Contributed fix for #51: `YearKeyDeserializer` doesn't work with non-padded
66+
year values
67+
(2.10.0)

release-notes/VERSION-2.x

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ Modules:
88
=== Releases ===
99
------------------------------------------------------------------------
1010

11-
2.10.0.pr2
11+
2.10.0 (not yet released)
12+
13+
#51: `YearKeyDeserializer` doesn't work with non-padded year values
14+
(reported by sladkoff@github; fix contributed by Mike [kupci@github])
15+
16+
2.10.0.pr2 (31-Aug-2019)
1217
1318
#69: `ZonedDateTime` for times before the epoch do not serialize correctly
1419
(fixed by Mike [kupci@github])

0 commit comments

Comments
 (0)