如何从自定义Gson JsonSerializer调用另一个序列化程序?
2022-09-04 21:29:10
我有我的自定义类:User
class User {
public String name;
public int id;
public Address address;
public Timestamp created;
}
我现在正在为用户创建自定义 JsonSerializer.class:
@Override
public JsonElement serialize(User src, Type typeOfSrc,
JsonSerializationContext context) {
JsonObject obj = new JsonObject();
obj.addProperty("name", src.name);
obj.addProperty("id", src.id);
obj.addProperty("address", src.address.id);
// Want to invoke another JsonSerializer (TimestampAdapter) for Timestamp
obj.add("created", ???);
return obj;
}
但是我已经有一个我用于.如何调用它以在 ?TimestampAdapter
Timestamp.class
JsonSerializer
User.class