Closed GoogleCodeExporter closed 9 years ago
Fixed by r721.
Original comment by limpbizkit
on 10 Feb 2011 at 1:07
It will be great if we can configure GsonBuilder to force used of ISO-8601
format with UTC timezone, for serialization and deserialization.
Thanks
Original comment by boillodm...@gmail.com
on 14 Jun 2011 at 10:03
[deleted comment]
private static class GmtDateTypeAdapter implements JsonSerializer<Date>,
JsonDeserializer<Date> {
private final DateFormat dateFormat;
private GmtDateTypeAdapter() {
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}
@Override
public synchronized JsonElement serialize(Date date, Type type,
JsonSerializationContext jsonSerializationContext) {
synchronized (dateFormat) {
String dateFormatAsString = dateFormat.format(date);
return new JsonPrimitive(dateFormatAsString);
}
}
@Override
public synchronized Date deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext jsonDeserializationContext) {
try {
synchronized (dateFormat) {
return dateFormat.parse(jsonElement.getAsString());
}
} catch (ParseException e) {
throw new JsonSyntaxException(jsonElement.getAsString(), e);
}
}
}
Original comment by boillodm...@gmail.com
on 14 Jun 2011 at 12:36
+1 ! And it would be nice to be able to specify the DateFormat and not just
only the SDF pattern on the GsonBuilder
Original comment by lorber.s...@gmail.com
on 15 Mar 2013 at 2:46
Which version of gson has this fix ?
Original comment by misramay...@gmail.com
on 3 Jul 2014 at 9:48
Original issue reported on code.google.com by
limpbizkit
on 30 Jan 2011 at 1:01