Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On StackOverflow I have answered for question: How to deserialize from #62

Merged
merged 1 commit into from
May 27, 2015
Merged
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 @@ -22,14 +22,14 @@ public class LocalDateDeserializer
@Override
public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// [yyyy,mm,dd]
// [yyyy,mm,dd] or ["yyyy","mm","dd"]
if (jp.isExpectedStartArrayToken()) {
jp.nextToken(); // VALUE_NUMBER_INT
int year = jp.getIntValue();
jp.nextToken(); // VALUE_NUMBER_INT
int month = jp.getIntValue();
jp.nextToken(); // VALUE_NUMBER_INT
int day = jp.getIntValue();
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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ public void testLocalDateDeserWithTypeInfo() throws IOException
assertEquals(7, date2.getMonthOfYear());
assertEquals(13, date2.getDayOfMonth());
}

public void testLocalDateDeserWithPartsAsString() throws IOException
{
// couple of acceptable formats, so:
LocalDate date = MAPPER.readValue("[\"2001\",\"5\",\"25\"]", LocalDate.class);
assertEquals(2001, date.getYear());
assertEquals(5, date.getMonthOfYear());
assertEquals(25, date.getDayOfMonth());
}

/*
/**********************************************************
Expand Down