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

Commit da6532d

Browse files
committed
Fixed #76 as per suggestion, just slightly reworked to use shared base method
1 parent 535c06a commit da6532d

30 files changed

+96
-79
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<!-- Java8 takes Javadoc-Nazi attitude, insert some sanity here -->
3333
<additionalparam>-Xdoclint:none</additionalparam>
3434

35-
<version.jackson.core>2.7.3</version.jackson.core>
35+
<version.jackson.core>2.7.4-SNAPSHOT</version.jackson.core>
3636

3737
<!-- Generate PackageVersion.java into this directory. -->
3838
<packageVersion.dir>com/fasterxml/jackson/datatype/jsr310</packageVersion.dir>

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Project: jackson-datatype-jsr310
1010
(contributed by Arzie@github)
1111
#71: Add LICENSE file in jar that is built
1212
(reported by puntogil@github)
13+
#76: Use `InvalidFormatException` for deserialization parse failures
14+
(suggested by Mike W)
1315

1416
2.7.3 (16-Mar-2016)
1517

src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/DurationDeserializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ public Duration deserialize(JsonParser parser, DeserializationContext context) t
6363

6464
case JsonTokenId.ID_STRING:
6565
String string = parser.getText().trim();
66-
if(string.length() == 0) {
66+
if (string.length() == 0) {
6767
return null;
6868
}
6969
try {
7070
return Duration.parse(string);
7171
} catch (DateTimeException e) {
72-
_rethrowDateTimeException(parser, e);
72+
_rethrowDateTimeException(parser, context, e, string);
7373
}
7474
}
7575
throw context.mappingException("Expected type float, integer, or string.");

src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/InstantDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public T deserialize(JsonParser parser, DeserializationContext context) throws I
153153
return adjust.apply(value, this.getZone(context));
154154
}
155155
} catch (DateTimeException e) {
156-
_rethrowDateTimeException(parser, e);
156+
_rethrowDateTimeException(parser, context, e, string);
157157
value = null;
158158
}
159159
return value;

src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/JSR310DeserializerBase.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.time.DateTimeException;
21+
import java.time.format.DateTimeParseException;
2122

2223
import com.fasterxml.jackson.core.JsonParser;
2324
import com.fasterxml.jackson.core.JsonToken;
@@ -55,11 +56,19 @@ protected void _reportWrongToken(JsonParser parser, DeserializationContext conte
5556
"Expected "+exp.name()+" for '"+unit+"' of "+handledType().getName()+" value");
5657
}
5758

58-
protected void _rethrowDateTimeException(JsonParser p, DateTimeException e) throws IOException
59+
protected void _rethrowDateTimeException(JsonParser p, DeserializationContext context,
60+
DateTimeException e0, String value) throws JsonMappingException
5961
{
60-
throw JsonMappingException.from(p,
62+
JsonMappingException e;
63+
if (e0 instanceof DateTimeParseException) {
64+
e = context.weirdStringException(value, handledType(), e0.getMessage());
65+
e.initCause(e0);
66+
} else {
67+
e = JsonMappingException.from(p,
6168
String.format("Failed to deserialize %s: (%s) %s",
62-
handledType().getName(), e.getClass().getName(), e.getMessage()), e);
69+
handledType().getName(), e0.getClass().getName(), e0.getMessage()), e0);
70+
}
71+
throw e;
6372
}
6473

6574
/**

src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/JSR310StringParsableDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Object deserialize(JsonParser parser, DeserializationContext context) thr
8888
return ZoneOffset.of(string);
8989
}
9090
} catch (DateTimeException e) {
91-
_rethrowDateTimeException(parser, e);
91+
_rethrowDateTimeException(parser, context, e, string);
9292
}
9393
}
9494
throw context.wrongTokenException(parser, JsonToken.VALUE_STRING, null);

src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/LocalDateDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public LocalDate deserialize(JsonParser parser, DeserializationContext context)
7979
}
8080
return LocalDate.parse(string, format);
8181
} catch (DateTimeException e) {
82-
_rethrowDateTimeException(parser, e);
82+
_rethrowDateTimeException(parser, context, e, string);
8383
}
8484
}
8585
if (parser.isExpectedStartArrayToken()) {

src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/LocalDateTimeDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public LocalDateTime deserialize(JsonParser parser, DeserializationContext conte
8282

8383
return LocalDateTime.parse(string, _formatter);
8484
} catch (DateTimeException e) {
85-
_rethrowDateTimeException(parser, e);
85+
_rethrowDateTimeException(parser, context, e, string);
8686
}
8787
}
8888
if (parser.isExpectedStartArrayToken()) {

src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/LocalTimeDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public LocalTime deserialize(JsonParser parser, DeserializationContext context)
7171
}
7272
return LocalTime.parse(string, format);
7373
} catch (DateTimeException e) {
74-
_rethrowDateTimeException(parser, e);
74+
_rethrowDateTimeException(parser, context, e, string);
7575
}
7676
}
7777
if (parser.isExpectedStartArrayToken()) {

src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/MonthDayDeserializer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ protected JsonDeserializer<MonthDay> withDateFormat(DateTimeFormatter dtf) {
3232
public MonthDay deserialize(JsonParser parser, DeserializationContext context) throws IOException
3333
{
3434
if (parser.hasToken(JsonToken.VALUE_STRING)) {
35-
String str = parser.getValueAsString().trim();
35+
String string = parser.getValueAsString().trim();
3636
try {
3737
if (_formatter == null) {
38-
return MonthDay.parse(str);
38+
return MonthDay.parse(string);
3939
}
40-
return MonthDay.parse(str, _formatter);
40+
return MonthDay.parse(string, _formatter);
4141
} catch (DateTimeException e) {
42-
_rethrowDateTimeException(parser, e);
42+
_rethrowDateTimeException(parser, context, e, string);
4343
}
4444
}
4545
throw context.mappingException("Unexpected token (%s), expected VALUE_STRING or VALUE_NUMBER_INT",

0 commit comments

Comments
 (0)