我有我的自定义类User:
class User {
public String name;
public int id;
public Address address;
public Timestamp created;
}
Run Code Online (Sandbox Code Playgroud)
我现在正在为User.class创建一个自定义的JsonSerializer:
@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;
}
Run Code Online (Sandbox Code Playgroud)
但我已经有了一个TimestampAdapter我用的Timestamp.class.我怎样才能调用它JsonSerializer来在"创建"字段中使用User.class?