Skip to content

Commit

Permalink
Update release notes, minor cleanup wrt #71
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 15, 2015
1 parent 7939d83 commit 77d2ddd
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 37 deletions.
7 changes: 7 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ Jerry Yang (islanerman@github)
jamesmcmillan@github
* Reported #70: Default DateTime parser format is stricter than
previous versions, causing incompatibility

Luke Nezda (nezda@github)

* Contributed #71: Adjust LocalDate / LocalDateTime deserializer to support
`DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE`
(2.6.2)

4 changes: 3 additions & 1 deletion release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Project: jackson-datatype-joda

2.6.2 (15-Sep-2015)

No changes since 2.6.1
#71: Adjust LocalDate / LocalDateTime deserializer to support
`DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE`
(contributed by Luke N)

2.6.1 (09-Aug-2015)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.JsonTokenId;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.datatype.joda.cfg.FormatConfig;
import com.fasterxml.jackson.datatype.joda.cfg.JacksonJodaDateFormat;
Expand All @@ -31,17 +33,18 @@ public JodaDateDeserializerBase<?> withFormat(JacksonJodaDateFormat format) {
@Override
public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
if (p.getCurrentToken() == JsonToken.VALUE_STRING) {
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_STRING:
String str = p.getText().trim();
return (str.length() == 0) ? null
: _format.createParser(ctxt).parseLocalDate(str);
}
if (p.getCurrentToken() == JsonToken.VALUE_NUMBER_INT) {
return new LocalDate(p.getLongValue(), DateTimeZone.forTimeZone(ctxt.getTimeZone()));
}

// [yyyy,mm,dd] or ["yyyy","mm","dd"]
if (p.isExpectedStartArrayToken()) {
case JsonTokenId.ID_NUMBER_INT:
{
DateTimeZone tz = _format.isTimezoneExplicit() ? _format.getTimeZone() : DateTimeZone.forTimeZone(ctxt.getTimeZone());
return new LocalDate(p.getLongValue(), tz);
}
case JsonTokenId.ID_START_ARRAY:
// [yyyy,mm,dd] or ["yyyy","mm","dd"]
int year = p.nextIntValue(-1); // fast speculative case
if (year == -1) { // either -1, or not an integral number; slow path
year = _parseIntPrimitive(p, ctxt);
Expand All @@ -61,4 +64,4 @@ public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws I
}
throw ctxt.wrongTokenException(p, JsonToken.START_ARRAY, "expected String, Number or JSON Array");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDateTime;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.datatype.joda.cfg.FormatConfig;
import com.fasterxml.jackson.datatype.joda.cfg.JacksonJodaDateFormat;
Expand All @@ -33,43 +33,55 @@ public JodaDateDeserializerBase<?> withFormat(JacksonJodaDateFormat format) {
public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException
{
switch (p.getCurrentToken()) {
case VALUE_STRING:
String str = p.getText().trim();
return (str.length() == 0) ? null
: _format.createParser(ctxt).parseLocalDateTime(str);
case VALUE_NUMBER_INT:
return new LocalDateTime(p.getLongValue(), DateTimeZone.forTimeZone(ctxt.getTimeZone()));
case START_ARRAY:
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_STRING:
{
String str = p.getText().trim();
return (str.length() == 0) ? null
: _format.createParser(ctxt).parseLocalDateTime(str);
}
case JsonTokenId.ID_NUMBER_INT:
{
DateTimeZone tz = _format.isTimezoneExplicit() ? _format.getTimeZone() : DateTimeZone.forTimeZone(ctxt.getTimeZone());
return new LocalDateTime(p.getLongValue(), tz);
}
case JsonTokenId.ID_START_ARRAY:
// [yyyy,mm,dd,hh,MM,ss,ms]
if (p.isExpectedStartArrayToken()) {
p.nextToken(); // VALUE_NUMBER_INT
JsonToken t = p.nextToken();
LocalDateTime dt = null;
do {
if (!t.isNumeric()) { break; }
int year = p.getIntValue();
p.nextToken(); // VALUE_NUMBER_INT
t = p.nextToken(); // VALUE_NUMBER_INT
if (!t.isNumeric()) { break; }
int month = p.getIntValue();
p.nextToken(); // VALUE_NUMBER_INT
t = p.nextToken(); // VALUE_NUMBER_INT
if (!t.isNumeric()) { break; }
int day = p.getIntValue();
p.nextToken(); // VALUE_NUMBER_INT
t = p.nextToken(); // VALUE_NUMBER_INT
if (!t.isNumeric()) { break; }
int hour = p.getIntValue();
p.nextToken(); // VALUE_NUMBER_INT
t = p.nextToken(); // VALUE_NUMBER_INT
if (!t.isNumeric()) { break; }
int minute = p.getIntValue();
p.nextToken(); // VALUE_NUMBER_INT
t = p.nextToken(); // VALUE_NUMBER_INT
if (!t.isNumeric()) { break; }
int second = p.getIntValue();
p.nextToken(); // VALUE_NUMBER_INT | END_ARRAY
t = p.nextToken(); // VALUE_NUMBER_INT | END_ARRAY
// let's leave milliseconds optional?
int millisecond = 0;
if (p.getCurrentToken() != JsonToken.END_ARRAY) { // VALUE_NUMBER_INT
if (t.isNumeric()) { // VALUE_NUMBER_INT
millisecond = p.getIntValue();
p.nextToken(); // END_ARRAY?
}
if (p.getCurrentToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY, "after LocalDateTime ints");
t = p.nextToken(); // END_ARRAY?
}
return new LocalDateTime(year, month, day, hour, minute, second, millisecond);
dt = new LocalDateTime(year, month, day, hour, minute, second, millisecond);
} while (false); // bogus loop to allow break from within
if (t == JsonToken.END_ARRAY) {
return dt;
}
break;
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY, "after LocalDateTime ints");
default:
}
throw ctxt.wrongTokenException(p, JsonToken.START_ARRAY, "expected JSON Array, Number or String");
throw ctxt.wrongTokenException(p, JsonToken.START_ARRAY, "expected String, Number or JSON Array");
}
}
}

0 comments on commit 77d2ddd

Please sign in to comment.