Closed GoogleCodeExporter closed 9 years ago
Сonfirm this bug:
------------
Gson g = new GsonBuilder().create();//setDateFormat("'Date('yyyy-MM-
dd'T'HH:mm:ss.SSSZ')'").create();
throw new Exception(g.toJson(item.shiftBegin) + "----" +
item.shiftBegin.toString());
------------
"{nanos:0}----2010-05-03 00:00:00.0"
Original comment by saph...@gmail.com
on 5 May 2010 at 6:49
It's not bug :)
returning field from database is "java.sql.Timestamp"
solution:
...
static private class sqlTimestampConverter implements JsonSerializer<Timestamp> {
static SimpleDateFormat sdf = new SimpleDateFormat("'Date('yyyy-MM-
dd'T'HH:mm:ss.SSSZ')'");
@Override
public JsonElement serialize(Timestamp src, Type srcType,
JsonSerializationContext context) {
return new JsonPrimitive(sdf.format(src));
}
}
...
GsonBuilder gson = new GsonBuilder().setDateFormat("'Date('yyyy-MM-
dd'T'HH:mm:ss.SSSZ')'");
gson.registerTypeAdapter(Timestamp.class, new sqlTimestampConverter());
Original comment by saph...@gmail.com
on 7 May 2010 at 8:39
Thanks saphsys.
Original comment by limpbizkit
on 3 Sep 2010 at 6:34
Original issue reported on code.google.com by
wuguangjian
on 21 Mar 2010 at 7:22