Skip to content

Commit

Permalink
Merge branch '2.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 30, 2020
2 parents 23e3cec + 7a193a0 commit d0bd022
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}

0 comments on commit d0bd022

Please sign in to comment.