8
8
import com .fasterxml .jackson .core .JsonParser ;
9
9
import com .fasterxml .jackson .core .JsonToken ;
10
10
import com .fasterxml .jackson .core .JsonTokenId ;
11
-
11
+ import com .fasterxml .jackson .core .StreamReadCapability ;
12
+ import com .fasterxml .jackson .core .io .NumberInput ;
12
13
import com .fasterxml .jackson .databind .DeserializationContext ;
13
14
import com .fasterxml .jackson .datatype .joda .cfg .FormatConfig ;
14
15
import com .fasterxml .jackson .datatype .joda .cfg .JacksonJodaDateFormat ;
@@ -37,13 +38,18 @@ public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws I
37
38
switch (p .currentTokenId ()) {
38
39
case JsonTokenId .ID_STRING :
39
40
String str = p .getText ().trim ();
40
- return (str .length () == 0 ) ? null
41
- : _format .createParser (ctxt ).parseLocalDate (str );
42
- case JsonTokenId .ID_NUMBER_INT :
43
- {
44
- DateTimeZone tz = _format .isTimezoneExplicit () ? _format .getTimeZone () : DateTimeZone .forTimeZone (ctxt .getTimeZone ());
45
- return new LocalDate (p .getLongValue (), tz );
41
+ if (str .length () == 0 ) {
42
+ return getNullValue (ctxt );
43
+ }
44
+ // 14-Jul-2020: [datatype-joda#117] Should allow use of "Timestamp as String" for
45
+ // some textual formats
46
+ if (ctxt .isEnabled (StreamReadCapability .UNTYPED_SCALARS )
47
+ && _isValidTimestampString (str )) {
48
+ return _fromTimestamp (ctxt , NumberInput .parseLong (str ));
46
49
}
50
+ return _format .createParser (ctxt ).parseLocalDate (str );
51
+ case JsonTokenId .ID_NUMBER_INT :
52
+ return _fromTimestamp (ctxt , p .getLongValue ());
47
53
case JsonTokenId .ID_START_ARRAY :
48
54
// [yyyy,mm,dd] or ["yyyy","mm","dd"]
49
55
int year = p .nextIntValue (-1 ); // fast speculative case
@@ -63,7 +69,13 @@ public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws I
63
69
}
64
70
return new LocalDate (year , month , day );
65
71
}
66
- return (LocalDate ) ctxt .handleUnexpectedToken (handledType (), p .getCurrentToken (), p ,
72
+ return (LocalDate ) ctxt .handleUnexpectedToken (handledType (), p .currentToken (), p ,
67
73
"expected String, Number or JSON Array" );
68
74
}
75
+
76
+ protected LocalDate _fromTimestamp (DeserializationContext ctxt , long ts ) {
77
+ DateTimeZone tz = _format .isTimezoneExplicit () ? _format .getTimeZone ()
78
+ : DateTimeZone .forTimeZone (ctxt .getTimeZone ());
79
+ return new LocalDate (ts , tz );
80
+ }
69
81
}
0 commit comments