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

[BUGFIX] Correctly deserialize ISO 8601 string with timezone offset #44

Merged
merged 1 commit into from
Feb 3, 2019
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 @@ -87,7 +87,7 @@ public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationC
return null;
}

final DateTimeFormatter fmt = ISODateTimeFormat.dateTimeParser();
final DateTimeFormatter fmt = ISODateTimeFormat.dateTimeParser().withOffsetParsed();
return fmt.parseDateTime(json.getAsString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,17 @@ public void testDeserializeWithoutMilliseconds()

assertThat(gson.fromJson(str, DateTime.class), is(expected));
}

/**
* Tests that deserialising an ISO 8601 string with a timezone offset works
*/
@Test
public void testDeserializeWithTimezoneOffset()
{
final Gson gson = Converters.registerDateTime(new GsonBuilder()).create();
final String str = "2019-01-31T10:37:20.631+01:00";
final String json = "\"" + str + "\"";

assertThat(gson.fromJson(json, DateTime.class).toString(), is(str));
}
}