Jacksonはjson文字列を汎用リストに変換し、Map

535 ワード

複雑なタイプが汎用であるCollection Typeを逆シーケンス化する必要がある
ArrayListの場合、ObjectMapperのgettypeFactory()/constructParametricType(ArrayList.class,YourBean.class)を使用します.
ObjectMapper mapper = new ObjectMapper();
JavaType javaType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, YourBean.class));
List lst =  (List)mapper.readValue(jsonString, javaType); 

HashMapの場合ObjectMapperのgettypeFactory().constructParametricType(HashMap.class,String.class,YourBean.class);