11package com .fasterxml .jackson .datatype .jsr310 .deser ;
22
3+ import java .io .IOException ;
4+ import java .time .Month ;
5+ import java .time .YearMonth ;
6+ import java .time .format .DateTimeParseException ;
7+ import java .util .Map ;
8+
39import com .fasterxml .jackson .annotation .JsonFormat ;
410import com .fasterxml .jackson .core .JsonProcessingException ;
511import com .fasterxml .jackson .core .type .TypeReference ;
612import com .fasterxml .jackson .databind .DeserializationFeature ;
713import com .fasterxml .jackson .databind .JsonMappingException ;
814import com .fasterxml .jackson .databind .ObjectMapper ;
915import com .fasterxml .jackson .databind .ObjectReader ;
16+ import com .fasterxml .jackson .databind .SerializationFeature ;
1017import com .fasterxml .jackson .databind .exc .MismatchedInputException ;
1118import com .fasterxml .jackson .datatype .jsr310 .ModuleTestBase ;
1219
1320import org .junit .Test ;
1421
15- import java .io .IOException ;
16- import java .time .Month ;
17- import java .time .YearMonth ;
18- import java .time .format .DateTimeParseException ;
19- import java .util .Map ;
20-
2122import static org .junit .Assert .assertEquals ;
2223import static org .junit .Assert .assertNotNull ;
2324import static org .junit .Assert .assertNull ;
2425import static org .junit .Assert .fail ;
2526
2627public class YearMonthDeserTest extends ModuleTestBase
2728{
28- private final ObjectReader READER = newMapper ().readerFor (YearMonth .class );
29+ private final ObjectMapper MAPPER = newMapper ();
30+ private final ObjectReader READER = MAPPER .readerFor (YearMonth .class );
2931 private final TypeReference <Map <String , YearMonth >> MAP_TYPE_REF = new TypeReference <Map <String , YearMonth >>() { };
3032
3133 @ Test
@@ -35,52 +37,63 @@ public void testDeserializationAsString01() throws Exception
3537 }
3638
3739 @ Test
38- public void testBadDeserializationAsString01 () throws Throwable
40+ public void testBadDeserializationAsString01 () throws Exception
3941 {
4042 expectFailure ("'notayearmonth'" );
4143 }
4244
4345 @ Test
44- public void testDeserializationAsArrayDisabled () throws Throwable
46+ public void testDeserializationAsArrayDisabled () throws Exception
4547 {
46- try {
47- read ("['2000-01']" );
48- fail ("expected JsonMappingException" );
48+ try {
49+ read ("['2000-01']" );
50+ fail ("expected JsonMappingException" );
4951 } catch (JsonMappingException e ) {
5052 // OK
5153 } catch (IOException e ) {
5254 throw e ;
5355 }
54-
5556 }
5657
5758 @ Test
58- public void testDeserializationAsEmptyArrayDisabled () throws Throwable
59+ public void testDeserializationAsEmptyArrayDisabled () throws Exception
5960 {
60- // works even without the feature enabled
61- assertNull (read ("[]" ));
61+ // works even without the feature enabled
62+ assertNull (read ("[]" ));
6263 }
6364
6465 @ Test
65- public void testDeserializationAsArrayEnabled () throws Throwable
66+ public void testDeserializationAsArrayEnabled () throws Exception
6667 {
67- String json ="['2000-01']" ;
68- YearMonth value = newMapper ()
69- .configure (DeserializationFeature .UNWRAP_SINGLE_VALUE_ARRAYS , true )
70- .readerFor (YearMonth .class ).readValue (a2q (json ));
71- notNull (value );
68+ String json ="['2000-01']" ;
69+ YearMonth value = newMapper ()
70+ .configure (DeserializationFeature .UNWRAP_SINGLE_VALUE_ARRAYS , true )
71+ .readerFor (YearMonth .class ).readValue (a2q (json ));
72+ notNull (value );
7273 expect (YearMonth .of (2000 , Month .JANUARY ), value );
7374 }
7475
7576 @ Test
76- public void testDeserializationAsEmptyArrayEnabled () throws Throwable
77+ public void testDeserializationAsEmptyArrayEnabled () throws Exception
78+ {
79+ String json ="[]" ;
80+ YearMonth value = newMapper ()
81+ .configure (DeserializationFeature .UNWRAP_SINGLE_VALUE_ARRAYS , true )
82+ .configure (DeserializationFeature .ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT , true )
83+ .readerFor (YearMonth .class ).readValue (a2q (json ));
84+ assertNull (value );
85+ }
86+
87+ // [modules-java8#249
88+ @ Test
89+ public void testYearAbove10k () throws Exception
7790 {
78- String json = "[]" ;
79- YearMonth value = newMapper ()
80- . configure ( DeserializationFeature . UNWRAP_SINGLE_VALUE_ARRAYS , true )
81- . configure ( DeserializationFeature . ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT , true )
82- . readerFor ( YearMonth . class ). readValue (a2q ( json ) );
83- assertNull ( value );
91+ YearMonth input = YearMonth . of ( 10000 , 1 ) ;
92+ String json = MAPPER . writer ()
93+ . without ( SerializationFeature . WRITE_DATES_AS_TIMESTAMPS )
94+ . writeValueAsString ( input );
95+ YearMonth result = READER . readValue (json );
96+ expect ( input , result );
8497 }
8598
8699 /*
@@ -126,7 +139,7 @@ public void testStrictDeserializeFromEmptyString() throws Exception {
126139 objectReader .readValue (valueFromEmptyStr );
127140 }
128141
129- private void expectFailure (String json ) throws Throwable {
142+ private void expectFailure (String json ) throws Exception {
130143 try {
131144 read (json );
132145 fail ("expected DateTimeParseException" );
@@ -135,20 +148,20 @@ private void expectFailure(String json) throws Throwable {
135148 throw e ;
136149 }
137150 if (!(e .getCause () instanceof DateTimeParseException )) {
138- throw e .getCause ();
151+ throw ( Exception ) e .getCause ();
139152 }
140153 } catch (IOException e ) {
141154 throw e ;
142155 }
143156 }
144157
145- private void expectSuccess (Object exp , String json ) throws IOException {
158+ private void expectSuccess (Object exp , String json ) throws Exception {
146159 final YearMonth value = read (json );
147160 notNull (value );
148161 expect (exp , value );
149162 }
150163
151- private YearMonth read (final String json ) throws IOException {
164+ private YearMonth read (final String json ) throws Exception {
152165 return READER .readValue (a2q (json ));
153166 }
154167
0 commit comments