There is a class:

public class Entity<T extends Serializable, E extends Serializable> implements Serializable { private T data; private E error; public Entity() { } public T getData() { return data; } public void setData(T data) { this.data = data; } public E getError() { return error; } public void setError(E error) { this.error = error; } } 

And there is another class:

 public class Client implements Serializable { private String name; private Integer num; public Client() { } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getNum() { return num; } public void setNum(Integer num) { this.num = num; } } 

Can I parse the following json somehow:

 {"data": { "name": "none", "num": 12}, "error":null} 

    1 answer 1

    Desearization occurs automatically, all you need is parse json to java pojo. You can use gson but I recommend Jackson Mapper better, it is very easy to use and you can easily figure out how to do this using examples. If you want to do this in Spring MVC, you can specify (@RequestBody YourObject ojb) but first click the Jackson and it will do it automatically.

    • I understand what can be done like this: mapper.readValue (entity, Entity.class), and how can I do something like mapper.readValue (entity, Entity <Client, Error> .class)? - Max Art
    • 2
      @MaxArt I think you should look in the direction of TypeReference - fasterxml.imtqy.com/jackson-core/javadoc/2.0.0/com/fasterxml/… - Vartlok