diff --git a/src/main/java/com/fatboyindustrial/gsonjodatime/DateTimeConverter.java b/src/main/java/com/fatboyindustrial/gsonjodatime/DateTimeConverter.java index a8cecb8..93b083b 100644 --- a/src/main/java/com/fatboyindustrial/gsonjodatime/DateTimeConverter.java +++ b/src/main/java/com/fatboyindustrial/gsonjodatime/DateTimeConverter.java @@ -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()); } } diff --git a/src/test/java/com/fatboyindustrial/gsonjodatime/DateTimeConverterTest.java b/src/test/java/com/fatboyindustrial/gsonjodatime/DateTimeConverterTest.java index 74cf24c..3164221 100644 --- a/src/test/java/com/fatboyindustrial/gsonjodatime/DateTimeConverterTest.java +++ b/src/test/java/com/fatboyindustrial/gsonjodatime/DateTimeConverterTest.java @@ -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)); + } }