Skip to content

Commit a0eea1b

Browse files
committed
Update release notes wrt #62, minor tweak to patch
1 parent 6043941 commit a0eea1b

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

release-notes/CREDITS

+4
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ Charlie La Mothe (clamothe@github)
3131
Thorsten Platz (ThorstenPlatz@github)
3232
* Reported #60: Configured date/time format not considered when serializing Joda Instant
3333
(2.5.4)
34+
35+
Michał Ziober (ZioberMichal@github)
36+
* Contributed #62: Allow use of numbers-as-Strings for LocalDate (in array)
37+
(2.6.0)

release-notes/VERSION

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Project: jackson-datatype-joda
66

77
2.6.0 (not yet released)
88

9+
#62: Allow use of numbers-as-Strings for LocalDate (in array)
10+
(contributed by Michal Z)
11+
912
2.5.4 (not yet released)
1013

1114
#60: Configured date/time format not considered when serializing Joda Instant

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

+27-21
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,38 @@ public class LocalDateDeserializer
2020
public LocalDateDeserializer() { super(LocalDate.class); }
2121

2222
@Override
23-
public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
23+
public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
2424
{
25-
// [yyyy,mm,dd] or ["yyyy","mm","dd"]
26-
if (jp.isExpectedStartArrayToken()) {
27-
jp.nextToken(); // VALUE_NUMBER_INT or VALUE_STRING
28-
int year = new Integer(jp.getText());
29-
jp.nextToken(); // VALUE_NUMBER_INT or VALUE_STRING
30-
int month = new Integer(jp.getText());
31-
jp.nextToken(); // VALUE_NUMBER_INT or VALUE_STRING
32-
int day = new Integer(jp.getText());
33-
if (jp.nextToken() != JsonToken.END_ARRAY) {
34-
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY, "after LocalDate ints");
35-
}
36-
return new LocalDate(year, month, day);
37-
}
38-
switch (jp.getCurrentToken()) {
39-
case VALUE_NUMBER_INT:
40-
return new LocalDate(jp.getLongValue());
41-
case VALUE_STRING:
42-
String str = jp.getText().trim();
25+
if (p.getCurrentToken() == JsonToken.VALUE_STRING) {
26+
String str = p.getText().trim();
4327
if (str.length() == 0) { // [JACKSON-360]
4428
return null;
4529
}
4630
return parser.parseLocalDate(str);
47-
default:
4831
}
49-
throw ctxt.wrongTokenException(jp, JsonToken.START_ARRAY, "expected JSON Array, String or Number");
32+
if (p.getCurrentToken() == JsonToken.VALUE_NUMBER_INT) {
33+
return new LocalDate(p.getLongValue());
34+
}
35+
36+
// [yyyy,mm,dd] or ["yyyy","mm","dd"]
37+
if (p.isExpectedStartArrayToken()) {
38+
int year = p.nextIntValue(-1); // fast speculative case
39+
if (year == -1) { // either -1, or not an integral number; slow path
40+
year = _parseIntPrimitive(p, ctxt);
41+
}
42+
int month = p.nextIntValue(-1);
43+
if (month == -1) {
44+
month = _parseIntPrimitive(p, ctxt);
45+
}
46+
int day = p.nextIntValue(-1);
47+
if (day == -1) {
48+
day = _parseIntPrimitive(p, ctxt);
49+
}
50+
if (p.nextToken() != JsonToken.END_ARRAY) {
51+
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY, "after LocalDate ints");
52+
}
53+
return new LocalDate(year, month, day);
54+
}
55+
throw ctxt.wrongTokenException(p, JsonToken.START_ARRAY, "expected String, Number or JSON Array");
5056
}
5157
}

0 commit comments

Comments
 (0)