Skip to content

Commit 54010cf

Browse files
committed
Update release notes wrt #51
1 parent 710b051 commit 54010cf

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
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

149
public class YearKeyDeserializer extends Jsr310KeyDeserializer {
1510

1611
public static final YearKeyDeserializer INSTANCE = new YearKeyDeserializer();
1712

18-
private YearKeyDeserializer() {
13+
protected YearKeyDeserializer() {
1914
// singleton
2015
}
2116

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

+14-5
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@ 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")));
3338
}
3439

3540
@Test(expected = InvalidFormatException.class)
@@ -45,11 +50,15 @@ public void deserializeYearKey_notAYear() throws Exception {
4550
@Test
4651
public void serializeAndDeserializeYearKeyUnpadded() throws Exception {
4752
// fix for issue #51 verify we can deserialize an unpadded year e.g. "1"
48-
ObjectMapper unpaddedMapper = newMapper();
4953
Map<Year, Float> testMap = Collections.singletonMap(Year.of(1), 1F);
50-
String serialized = unpaddedMapper.writeValueAsString(testMap);
54+
String serialized = MAPPER.writeValueAsString(testMap);
5155
TypeReference<Map<Year, Float>> yearFloatTypeReference = new TypeReference<Map<Year, Float>>() {};
52-
Map<Year, Float> deserialized = unpaddedMapper.readValue(serialized, yearFloatTypeReference);
56+
Map<Year, Float> deserialized = MAPPER.readValue(serialized, yearFloatTypeReference);
5357
assertEquals(testMap, deserialized);
58+
59+
// actually, check padded as well just to make sure
60+
Map<Year, Float> deserialized2 = MAPPER.readValue(aposToQuotes("{'0001':1.0}"),
61+
yearFloatTypeReference);
62+
assertEquals(testMap, deserialized2);
5463
}
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

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Modules:
88
=== Releases ===
99
------------------------------------------------------------------------
1010

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+
1116
2.10.0.pr2 (31-Aug-2019)
1217
1318
#69: `ZonedDateTime` for times before the epoch do not serialize correctly

0 commit comments

Comments
 (0)