@@ -20,32 +20,38 @@ public class LocalDateDeserializer
20
20
public LocalDateDeserializer () { super (LocalDate .class ); }
21
21
22
22
@ Override
23
- public LocalDate deserialize (JsonParser jp , DeserializationContext ctxt ) throws IOException
23
+ public LocalDate deserialize (JsonParser p , DeserializationContext ctxt ) throws IOException
24
24
{
25
- // [yyyy,mm,dd] or ["yyyy","mm","dd"]
26
- if (jp .isExpectedStartArrayToken ()) {
27
- jp .nextToken (); // VALUE_NUMBER_INT or VALUE_STRING
28
- int year = new Integer (jp .getText ());
29
- jp .nextToken (); // VALUE_NUMBER_INT or VALUE_STRING
30
- int month = new Integer (jp .getText ());
31
- jp .nextToken (); // VALUE_NUMBER_INT or VALUE_STRING
32
- int day = new Integer (jp .getText ());
33
- if (jp .nextToken () != JsonToken .END_ARRAY ) {
34
- throw ctxt .wrongTokenException (jp , JsonToken .END_ARRAY , "after LocalDate ints" );
35
- }
36
- return new LocalDate (year , month , day );
37
- }
38
- switch (jp .getCurrentToken ()) {
39
- case VALUE_NUMBER_INT :
40
- return new LocalDate (jp .getLongValue ());
41
- case VALUE_STRING :
42
- String str = jp .getText ().trim ();
25
+ if (p .getCurrentToken () == JsonToken .VALUE_STRING ) {
26
+ String str = p .getText ().trim ();
43
27
if (str .length () == 0 ) { // [JACKSON-360]
44
28
return null ;
45
29
}
46
30
return parser .parseLocalDate (str );
47
- default :
48
31
}
49
- throw ctxt .wrongTokenException (jp , JsonToken .START_ARRAY , "expected JSON Array, String or Number" );
32
+ if (p .getCurrentToken () == JsonToken .VALUE_NUMBER_INT ) {
33
+ return new LocalDate (p .getLongValue ());
34
+ }
35
+
36
+ // [yyyy,mm,dd] or ["yyyy","mm","dd"]
37
+ if (p .isExpectedStartArrayToken ()) {
38
+ int year = p .nextIntValue (-1 ); // fast speculative case
39
+ if (year == -1 ) { // either -1, or not an integral number; slow path
40
+ year = _parseIntPrimitive (p , ctxt );
41
+ }
42
+ int month = p .nextIntValue (-1 );
43
+ if (month == -1 ) {
44
+ month = _parseIntPrimitive (p , ctxt );
45
+ }
46
+ int day = p .nextIntValue (-1 );
47
+ if (day == -1 ) {
48
+ day = _parseIntPrimitive (p , ctxt );
49
+ }
50
+ if (p .nextToken () != JsonToken .END_ARRAY ) {
51
+ throw ctxt .wrongTokenException (p , JsonToken .END_ARRAY , "after LocalDate ints" );
52
+ }
53
+ return new LocalDate (year , month , day );
54
+ }
55
+ throw ctxt .wrongTokenException (p , JsonToken .START_ARRAY , "expected String, Number or JSON Array" );
50
56
}
51
57
}
0 commit comments