Java は通常、Generics
コンパイル時にデータを消去しますが、その情報を取得する可能性があります (JacksonObjectMapper
はそれをかなりうまく行っています)。
私の問題: リストのプロパティを持つクラスがあります:
public class User {
public List<Long> listProp;//it is public only to keep the example simple
}
クラスのインスタンス (User.class) とプロパティ名 (listProp)を持つ正しいリスト型にプログラムで JSON 文字列をマップできるように、正しいTypeReference
(または?) を取得するにはどうすればよいですか? 私が意味するのはこれです:JavaType
Class
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>