How to (completely) deserialize json into a generic List?

后端 未结 2 1868
走了就别回头了
走了就别回头了 2021-01-21 04:45

When using an ObjectMapper to transform a json String into an entity, I can make it generic as:

public  E getConvertedAs(Strin         


        
2条回答
  •  自闭症患者
    2021-01-21 05:41

    public static  List fromJson(String in_string, Class in_type) throws JsonParseException, JsonMappingException, IOException{
        return new ObjectMapper().readValue(in_string, new TypeReference>() {});
    }
    

    Compiles on my computer. Note that I haven't tested it, though.

提交回复
热议问题