|
9 | 9 |
|
10 | 10 | import com.fasterxml.jackson.core.JsonParser;
|
11 | 11 | import com.fasterxml.jackson.core.JsonTokenId;
|
12 |
| - |
| 12 | +import com.fasterxml.jackson.core.StreamReadCapability; |
| 13 | +import com.fasterxml.jackson.core.io.NumberInput; |
13 | 14 | import com.fasterxml.jackson.databind.DeserializationContext;
|
14 | 15 | import com.fasterxml.jackson.databind.JsonDeserializer;
|
15 | 16 | import com.fasterxml.jackson.datatype.joda.cfg.FormatConfig;
|
@@ -48,8 +49,7 @@ public ReadableInstant deserialize(JsonParser p, DeserializationContext ctxt)
|
48 | 49 | DateTimeZone tz;
|
49 | 50 | switch (p.currentTokenId()) {
|
50 | 51 | case JsonTokenId.ID_NUMBER_INT:
|
51 |
| - tz = _format.isTimezoneExplicit() ? _format.getTimeZone() : DateTimeZone.forTimeZone(ctxt.getTimeZone()); |
52 |
| - return new DateTime(p.getLongValue(), tz); |
| 52 | + return _fromTimestamp(ctxt, p.getLongValue()); |
53 | 53 | case JsonTokenId.ID_STRING:
|
54 | 54 | String str = p.getText().trim();
|
55 | 55 | if (str.length() == 0) {
|
@@ -92,10 +92,23 @@ public ReadableInstant deserialize(JsonParser p, DeserializationContext ctxt)
|
92 | 92 | }
|
93 | 93 | return result;
|
94 | 94 | }
|
| 95 | + // 14-Jul-2020: [datatype-joda#117] Should allow use of "Timestamp as String" for |
| 96 | + // some textual formats |
| 97 | + if (ctxt.isEnabled(StreamReadCapability.UNTYPED_SCALARS) |
| 98 | + && _isValidTimestampString(str)) { |
| 99 | + return _fromTimestamp(ctxt, NumberInput.parseLong(str)); |
| 100 | + } |
| 101 | + |
95 | 102 | // Not sure if it should use timezone or not...
|
96 | 103 | // 15-Sep-2015, tatu: impl of 'createParser()' SHOULD handle all timezone/locale setup
|
97 | 104 | return _format.createParser(ctxt).parseDateTime(str);
|
98 | 105 | }
|
99 | 106 | return _handleNotNumberOrString(p, ctxt);
|
100 | 107 | }
|
| 108 | + |
| 109 | + protected DateTime _fromTimestamp(DeserializationContext ctxt, long ts) { |
| 110 | + DateTimeZone tz = _format.isTimezoneExplicit() ? _format.getTimeZone() |
| 111 | + : DateTimeZone.forTimeZone(ctxt.getTimeZone()); |
| 112 | + return new DateTime(ts, tz); |
| 113 | + } |
101 | 114 | }
|
0 commit comments