Best way to map json to a Java object

前端 未结 3 630
名媛妹妹
名媛妹妹 2021-01-13 12:49

I\'m using restTemplate to make a rquest to a servlet that returns a very simple representation of an object in json.

{
     \"id\":\"SomeID\"
     \"name\":         


        
3条回答
  •  伪装坚强ぢ
    2021-01-13 13:25

    Personally I would recommend Jackson. Its fairly lightweight, very fast and requires very little configuration. Here's an example of deserializing:

    @XmlRootElement
    public class MyBean {
        private String id;
        private String name;
    
        public MyBean() {
            super();
        }
    
        // Getters/Setters
    }
    
    
    String json = "...";
    MyBean bean = new ObjectMapper().readValue(json, MyBean.class);
    

提交回复
热议问题