Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

Use InvalidFormatException for deserialization parse failures #76

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

import java.io.IOException;
import java.math.BigDecimal;
import java.time.DateTimeException;
import java.time.Duration;
import java.time.format.DateTimeParseException;

/**
* Deserializer for Java 8 temporal {@link Duration}s.
Expand Down Expand Up @@ -68,8 +68,8 @@ public Duration deserialize(JsonParser parser, DeserializationContext context) t
}
try {
return Duration.parse(string);
} catch (DateTimeException e) {
_rethrowDateTimeException(parser, e);
} catch (DateTimeParseException e) {
throw context.weirdStringException(string, handledType(), e.getMessage());
}
}
throw context.mappingException("Expected type float, integer, or string.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -152,6 +153,8 @@ public T deserialize(JsonParser parser, DeserializationContext context) throws I
if (context.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)) {
return adjust.apply(value, this.getZone(context));
}
} catch (DateTimeParseException e) {
throw context.weirdStringException(string, handledType(), e.getMessage());
} catch (DateTimeException e) {
_rethrowDateTimeException(parser, e);
value = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Object deserialize(JsonParser parser, DeserializationContext context) thr
return ZoneOffset.of(string);
}
} catch (DateTimeException e) {
_rethrowDateTimeException(parser, e);
throw context.weirdStringException(string, handledType(), e.getMessage());
}
}
throw context.wrongTokenException(parser, JsonToken.VALUE_STRING, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.DeserializationContext;
Expand Down Expand Up @@ -78,6 +79,8 @@ public LocalDate deserialize(JsonParser parser, DeserializationContext context)
}
}
return LocalDate.parse(string, format);
} catch (DateTimeParseException e) {
throw context.weirdStringException(string, handledType(), e.getMessage());
} catch (DateTimeException e) {
_rethrowDateTimeException(parser, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
Expand Down Expand Up @@ -81,6 +82,8 @@ public LocalDateTime deserialize(JsonParser parser, DeserializationContext conte
}

return LocalDateTime.parse(string, _formatter);
} catch (DateTimeParseException e) {
throw context.weirdStringException(string, handledType(), e.getMessage());
} catch (DateTimeException e) {
_rethrowDateTimeException(parser, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

/**
* Deserializer for Java 8 temporal {@link LocalTime}s.
Expand Down Expand Up @@ -70,8 +70,8 @@ public LocalTime deserialize(JsonParser parser, DeserializationContext context)
}
}
return LocalTime.parse(string, format);
} catch (DateTimeException e) {
_rethrowDateTimeException(parser, e);
} catch (DateTimeParseException e) {
throw context.weirdStringException(string, handledType(), e.getMessage());
}
}
if (parser.isExpectedStartArrayToken()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.fasterxml.jackson.datatype.jsr310.deser;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.MonthDay;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
Expand Down Expand Up @@ -38,8 +38,8 @@ public MonthDay deserialize(JsonParser parser, DeserializationContext context) t
return MonthDay.parse(str);
}
return MonthDay.parse(str, _formatter);
} catch (DateTimeException e) {
_rethrowDateTimeException(parser, e);
} catch (DateTimeParseException e) {
throw context.weirdStringException(str, handledType(), e.getMessage());
}
}
throw context.mappingException("Unexpected token (%s), expected VALUE_STRING or VALUE_NUMBER_INT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package com.fasterxml.jackson.datatype.jsr310.deser;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.OffsetTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
Expand Down Expand Up @@ -59,8 +59,8 @@ public OffsetTime deserialize(JsonParser parser, DeserializationContext context)
}
try {
return OffsetTime.parse(string, _formatter);
} catch (DateTimeException e) {
_rethrowDateTimeException(parser, e);
} catch (DateTimeParseException e) {
throw context.weirdStringException(string, handledType(), e.getMessage());
}
}
if (!parser.isExpectedStartArrayToken()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import com.fasterxml.jackson.databind.DeserializationContext;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.Year;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

/**
* Deserializer for Java 8 temporal {@link Year}s.
Expand Down Expand Up @@ -60,8 +60,8 @@ public Year deserialize(JsonParser parser, DeserializationContext context) throw
return Year.parse(str);
}
return Year.parse(str, _formatter);
} catch (DateTimeException e) {
_rethrowDateTimeException(parser, e);
} catch (DateTimeParseException e) {
throw context.weirdStringException(str, handledType(), e.getMessage());
}
}
if (t == JsonToken.VALUE_NUMBER_INT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

/**
* Deserializer for Java 8 temporal {@link YearMonth}s.
Expand Down Expand Up @@ -64,8 +64,8 @@ public YearMonth deserialize(JsonParser parser, DeserializationContext context)
}
try {
return YearMonth.parse(string, _formatter);
} catch (DateTimeException e) {
_rethrowDateTimeException(parser, e);
} catch (DateTimeParseException e) {
throw context.weirdStringException(string, handledType(), e.getMessage());
}
}
if (parser.isExpectedStartArrayToken()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.fasterxml.jackson.datatype.jsr310.deser.key;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.Duration;
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.databind.DeserializationContext;

Expand All @@ -18,8 +18,8 @@ private DurationKeyDeserializer() {
protected Duration deserialize(String key, DeserializationContext ctxt) throws IOException {
try {
return Duration.parse(key);
} catch (DateTimeException e) {
return _rethrowDateTimeException(ctxt, Duration.class, e);
} catch (DateTimeParseException e) {
throw ctxt.weirdKeyException(Duration.class, key, e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.fasterxml.jackson.datatype.jsr310.deser.key;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.databind.DeserializationContext;

Expand All @@ -19,8 +19,8 @@ private InstantKeyDeserializer() {
protected Instant deserialize(String key, DeserializationContext ctxt) throws IOException {
try {
return DateTimeFormatter.ISO_INSTANT.parse(key, Instant::from);
} catch (DateTimeException e) {
return _rethrowDateTimeException(ctxt, Instant.class, e);
} catch (DateTimeParseException e) {
throw ctxt.weirdKeyException(Instant.class, key, e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.fasterxml.jackson.datatype.jsr310.deser.key;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.databind.DeserializationContext;

Expand All @@ -19,8 +19,8 @@ private LocalDateKeyDeserializer() {
protected LocalDate deserialize(String key, DeserializationContext ctxt) throws IOException {
try {
return LocalDate.parse(key, DateTimeFormatter.ISO_LOCAL_DATE);
} catch (DateTimeException e) {
return _rethrowDateTimeException(ctxt, LocalDate.class, e);
} catch (DateTimeParseException e) {
throw ctxt.weirdKeyException(LocalDate.class, key, e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.fasterxml.jackson.datatype.jsr310.deser.key;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.databind.DeserializationContext;

Expand All @@ -19,8 +19,8 @@ private LocalDateTimeKeyDeserializer() {
protected LocalDateTime deserialize(String key, DeserializationContext ctxt) throws IOException {
try {
return LocalDateTime.parse(key, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
} catch (DateTimeException e) {
return _rethrowDateTimeException(ctxt, LocalDateTime.class, e);
} catch (DateTimeParseException e) {
throw ctxt.weirdKeyException(LocalDateTime.class, key, e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.fasterxml.jackson.datatype.jsr310.deser.key;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.databind.DeserializationContext;

Expand All @@ -19,8 +19,8 @@ private LocalTimeKeyDeserializer() {
protected LocalTime deserialize(String key, DeserializationContext ctxt) throws IOException {
try {
return LocalTime.parse(key, DateTimeFormatter.ISO_LOCAL_TIME);
} catch (DateTimeException e) {
return _rethrowDateTimeException(ctxt, LocalTime.class, e);
} catch (DateTimeParseException e) {
throw ctxt.weirdKeyException(LocalTime.class, key, e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.MonthDay;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.databind.DeserializationContext;

Expand All @@ -31,8 +31,8 @@ private MonthDayKeyDeserializer() {
protected MonthDay deserialize(String key, DeserializationContext ctxt) throws IOException {
try {
return MonthDay.parse(key, PARSER);
} catch (DateTimeException e) {
return _rethrowDateTimeException(ctxt, MonthDay.class, e);
} catch (DateTimeParseException e) {
throw ctxt.weirdKeyException(MonthDay.class, key, e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.fasterxml.jackson.datatype.jsr310.deser.key;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.databind.DeserializationContext;

Expand All @@ -19,8 +19,8 @@ private OffsetDateTimeKeyDeserializer() {
protected OffsetDateTime deserialize(String key, DeserializationContext ctxt) throws IOException {
try {
return OffsetDateTime.parse(key, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
} catch (DateTimeException e) {
return _rethrowDateTimeException(ctxt, OffsetDateTime.class, e);
} catch (DateTimeParseException e) {
throw ctxt.weirdKeyException(OffsetDateTime.class, key, e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.fasterxml.jackson.datatype.jsr310.deser.key;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.OffsetTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.databind.DeserializationContext;

Expand All @@ -19,8 +19,8 @@ private OffsetTimeKeyDeserializer() {
protected OffsetTime deserialize(String key, DeserializationContext ctxt) throws IOException {
try {
return OffsetTime.parse(key, DateTimeFormatter.ISO_OFFSET_TIME);
} catch (DateTimeException e) {
return _rethrowDateTimeException(ctxt, OffsetTime.class, e);
} catch (DateTimeParseException e) {
throw ctxt.weirdKeyException(OffsetTime.class, key, e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.fasterxml.jackson.datatype.jsr310.deser.key;

import java.io.IOException;
import java.time.DateTimeException;
import java.time.Period;
import java.time.format.DateTimeParseException;

import com.fasterxml.jackson.databind.DeserializationContext;

Expand All @@ -18,8 +18,8 @@ private PeriodKeyDeserializer() {
protected Period deserialize(String key, DeserializationContext ctxt) throws IOException {
try {
return Period.parse(key);
} catch (DateTimeException e) {
return _rethrowDateTimeException(ctxt, Period.class, e);
} catch (DateTimeParseException e) {
throw ctxt.weirdKeyException(Period.class, key, e.getMessage());
}
}
}
Loading