Skip to content

Commit

Permalink
Update release notes wrt #62, minor tweak to patch
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 27, 2015
1 parent 6043941 commit a0eea1b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ Charlie La Mothe (clamothe@github)
Thorsten Platz (ThorstenPlatz@github)
* Reported #60: Configured date/time format not considered when serializing Joda Instant
(2.5.4)

Michał Ziober (ZioberMichal@github)
* Contributed #62: Allow use of numbers-as-Strings for LocalDate (in array)
(2.6.0)
3 changes: 3 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Project: jackson-datatype-joda

2.6.0 (not yet released)

#62: Allow use of numbers-as-Strings for LocalDate (in array)
(contributed by Michal Z)

2.5.4 (not yet released)

#60: Configured date/time format not considered when serializing Joda Instant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,38 @@ public class LocalDateDeserializer
public LocalDateDeserializer() { super(LocalDate.class); }

@Override
public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// [yyyy,mm,dd] or ["yyyy","mm","dd"]
if (jp.isExpectedStartArrayToken()) {
jp.nextToken(); // VALUE_NUMBER_INT or VALUE_STRING
int year = new Integer(jp.getText());
jp.nextToken(); // VALUE_NUMBER_INT or VALUE_STRING
int month = new Integer(jp.getText());
jp.nextToken(); // VALUE_NUMBER_INT or VALUE_STRING
int day = new Integer(jp.getText());
if (jp.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY, "after LocalDate ints");
}
return new LocalDate(year, month, day);
}
switch (jp.getCurrentToken()) {
case VALUE_NUMBER_INT:
return new LocalDate(jp.getLongValue());
case VALUE_STRING:
String str = jp.getText().trim();
if (p.getCurrentToken() == JsonToken.VALUE_STRING) {
String str = p.getText().trim();
if (str.length() == 0) { // [JACKSON-360]
return null;
}
return parser.parseLocalDate(str);
default:
}
throw ctxt.wrongTokenException(jp, JsonToken.START_ARRAY, "expected JSON Array, String or Number");
if (p.getCurrentToken() == JsonToken.VALUE_NUMBER_INT) {
return new LocalDate(p.getLongValue());
}

// [yyyy,mm,dd] or ["yyyy","mm","dd"]
if (p.isExpectedStartArrayToken()) {
int year = p.nextIntValue(-1); // fast speculative case
if (year == -1) { // either -1, or not an integral number; slow path
year = _parseIntPrimitive(p, ctxt);
}
int month = p.nextIntValue(-1);
if (month == -1) {
month = _parseIntPrimitive(p, ctxt);
}
int day = p.nextIntValue(-1);
if (day == -1) {
day = _parseIntPrimitive(p, ctxt);
}
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY, "after LocalDate ints");
}
return new LocalDate(year, month, day);
}
throw ctxt.wrongTokenException(p, JsonToken.START_ARRAY, "expected String, Number or JSON Array");
}
}

0 comments on commit a0eea1b

Please sign in to comment.