任何人都可以帮助我了解使用 Jackson 将此 POJO 转换为 json 的正确方法吗?
我如何获得此类的 wright 类型以将其传递给 readValue(content, valueType)
?
谢谢。
public class GcmMessages<T> {
int mType;
int mEmpId;
Date mDate;
T[] mBody;
public GcmMessages()
{
}
}
最佳答案
你想要的可能是一个TypeReference
:
final TypeReference<GcmMessage<Foo>> typeref
= new TypeReference<GcmMessage<Foo>>(){};
final GcmMessage<Foo> = mapper.readValue(yourSource, typeref);
不确定它如何处理“通用数组”,但从未尝试过。
关于java - Jackson DeSerialize Class with <T> (Generic) 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27347053/