Jackson - Deserialize Generic class variable

前端 未结 5 688
梦谈多话
梦谈多话 2020-12-07 00:33

I had posted the question wrongly. I am posting the question correctly here ...

I am getting a json string as a HTTP response. I know the structure of it. It is as

5条回答
  •  时光说笑
    2020-12-07 00:52

    Sample generic deserializing interface:

    public interface Deserializable {
        static final ObjectMapper mapper = new ObjectMapper();
    
        @SuppressWarnings("unchecked")
        default T deserialize(String rawJson) throws IOException {
            return mapper.readValue(rawJson, (Class) this.getClass());
        }
    }
    

提交回复
热议问题