如何为GSON编写自定义JSON反序列化器?
public class User{
int id;
String name;
Timestamp updateDate;}[{"id":1,"name":"Jonas","update_date":"1300962900226"},{"id":5,"name":"Test","date_date":"1304782298024"}]@Overridepublic User deserialize(JsonElement json, Type type,
JsonDeserializationContext context) throws JsonParseException {
return new User(
json.getAsJsonPrimitive().getAsInt(),
json.getAsString(),
json.getAsInt(),
(Timestamp)context.deserialize(json.getAsJsonPrimitive(),
Timestamp.class));}红糖糍粑
白板的微信
aluckdog
相关分类