@@ -21,15 +21,20 @@ public class YearAsKeyTest extends ModuleTestBase
21
21
private final ObjectReader READER = MAPPER .readerFor (TYPE_REF );
22
22
23
23
@ Test
24
- public void testSerialization () throws Exception {
24
+ public void testKeySerialization () throws Exception {
25
25
assertEquals ("Value is incorrect" , mapAsString ("3141" , "test" ),
26
26
MAPPER .writeValueAsString (asMap (Year .of (3141 ), "test" )));
27
27
}
28
28
29
29
@ Test
30
- public void testDeserialization () throws Exception {
30
+ public void testKeyDeserialization () throws Exception {
31
31
assertEquals ("Value is incorrect" , asMap (Year .of (3141 ), "test" ),
32
32
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" )));
33
38
}
34
39
35
40
@ Test (expected = InvalidFormatException .class )
@@ -45,11 +50,15 @@ public void deserializeYearKey_notAYear() throws Exception {
45
50
@ Test
46
51
public void serializeAndDeserializeYearKeyUnpadded () throws Exception {
47
52
// fix for issue #51 verify we can deserialize an unpadded year e.g. "1"
48
- ObjectMapper unpaddedMapper = newMapper ();
49
53
Map <Year , Float > testMap = Collections .singletonMap (Year .of (1 ), 1F );
50
- String serialized = unpaddedMapper .writeValueAsString (testMap );
54
+ String serialized = MAPPER .writeValueAsString (testMap );
51
55
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 );
53
57
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 );
54
63
}
55
64
}
0 commit comments