【发布时间】:2013-07-10 10:39:19
【问题描述】:
Java 通常会在编译时删除Generics 数据,但有可能获得该信息(Jackson ObjectMapper 做得很好)。
我的问题:我有一个具有 List 属性的类:
public class User {
public List<Long> listProp;//it is public only to keep the example simple
}
我怎样才能得到正确的TypeReference(或JavaType?),以便我可以通过编程将JSON字符串映射到正确的列表类型,具有Class类的实例(User.class)和属性名称(listProp)?我的意思是:
TypeReference typeReference = ...;//how to get the typeReference?
List<Long> correctList = om.readValue(jsonEntry.getValue(), typeReference);//this should return a List<Long> and not eg. a List<Integer>
【问题讨论】:
标签: java jackson type-erasure