diff --git a/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/InstantDeserializer.java b/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/InstantDeserializer.java index 39133085..39503e25 100644 --- a/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/InstantDeserializer.java +++ b/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/InstantDeserializer.java @@ -42,7 +42,8 @@ import java.util.regex.Pattern; /** - * Deserializer for Java 8 temporal {@link Instant}s, {@link OffsetDateTime}, and {@link ZonedDateTime}s. + * Deserializer for Java 8 temporal {@link Instant}s, {@link OffsetDateTime}, + * and {@link ZonedDateTime}s. * * @author Nick Williams * @since 2.2 diff --git a/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/YearDeserializer.java b/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/YearDeserializer.java index b0970576..d8f5d940 100644 --- a/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/YearDeserializer.java +++ b/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/YearDeserializer.java @@ -24,6 +24,8 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.core.StreamReadCapability; +import com.fasterxml.jackson.core.io.NumberInput; import com.fasterxml.jackson.databind.DeserializationContext; /** @@ -76,7 +78,7 @@ public Year deserialize(JsonParser parser, DeserializationContext context) throw context.extractScalarFromObject(parser, this, handledType())); } if (t == JsonToken.VALUE_NUMBER_INT) { - return Year.of(parser.getIntValue()); + return _fromNumber(context, parser.getIntValue()); } if (t == JsonToken.VALUE_EMBEDDED_OBJECT) { return (Year) parser.getEmbeddedObject(); @@ -88,22 +90,31 @@ public Year deserialize(JsonParser parser, DeserializationContext context) throw } protected Year _fromString(JsonParser p, DeserializationContext ctxt, - String string) throws IOException + String value) throws IOException { - string = string.trim(); - if (string.length() == 0) { + value = value.trim(); + if (value.length() == 0) { if (!isLenient()) { return _failForNotLenient(p, ctxt, JsonToken.VALUE_STRING); } return null; } + // 30-Sep-2020: Should allow use of "Timestamp as String" for XML/CSV + if (ctxt.isEnabled(StreamReadCapability.UNTYPED_SCALARS) + && _isValidTimestampString(value)) { + return _fromNumber(ctxt, NumberInput.parseInt(value)); + } try { if (_formatter == null) { - return Year.parse(string); + return Year.parse(value); } - return Year.parse(string, _formatter); + return Year.parse(value, _formatter); } catch (DateTimeException e) { - return _handleDateTimeFormatException(ctxt, e, _formatter, string); + return _handleDateTimeFormatException(ctxt, e, _formatter, value); } } + + protected Year _fromNumber(DeserializationContext ctxt, int value) { + return Year.of(value); + } }