简体   繁体   中英

How to send nested JSON input to Restful web service (using Java)?

How to send nested JSON input to Restful web service (using Java)?

eg. JSON input

{
  "item1": [
    {
      "name": "name1",
      "value": "value1",
      "subitems": [
        {
          "sname": "sname1",
          "svalue": "svalue1"
        },
        {
          "sname": "sname2",
          "svalue": "svalue2"
        }
      ],
      "attributes": [
        {
          "length": 25,
          "height": 25,
          "width": 30
        },
        {
          "length": 35,
          "height": 35,
          "width": 40
        }
      ]
    }
  ]
}

You can create a class to map you json like this :

     public class item {
        private String name;
        private String value;
        private List<SubItem> subitems;
        private List<Attribute> attributes;
        // add here getters, setters and constructor
     }

     public class SubItem{
        private String name;
        private String svalue;
        //add here getters, setters and constructor
     }
     public class Attribute{
        private Integer length;
        private Integer height;
        private Integer width;
        //add here getters, setters and constructor
     }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM