0

please help me to create the body request from the following output:

{
  "categoryIds": [
    [
      "4654-456465-4564",
      "4654-456465-9512"
    ]
  ],
  "lastUpdate": "1231",
  "controlStructureId": "4654-456465-4564",
  "controntrolId": "4654-456465-4564",
  "vehicleId": "4654-456465-4564"
}

My code:

 Map<String,Object> jsonBodyUsingMap = new HashMap<String,Object>();
        jsonBodyUsingMap.put("lastUpdate", "1231");
        jsonBodyUsingMap.put("controlStructureId", "4654-456465-4564");
        jsonBodyUsingMap.put("controntrolId", "4654-456465-4564");
        jsonBodyUsingMap.put("vehicleId", "4654-456465-4564");

But I have no idea with categoryIds, please help

Toyota
  • 33
  • 1
  • 5

1 Answers1

0

This will solve your problem. So just put as ArrayList within another ArrayList and it'll be converted to an array by whatever JSON converter you're using:

    Map<String,Object> jsonBodyUsingMap = new HashMap<String,Object>();
    jsonBodyUsingMap.put("lastUpdate", "1231");
    jsonBodyUsingMap.put("controlStructureId", "4654-456465-4564");
    jsonBodyUsingMap.put("controntrolId", "4654-456465-4564");
    jsonBodyUsingMap.put("vehicleId", "4654-456465-4564");

    List<Object> categories = new ArrayList<>();
    List<String> subcategories = new ArrayList<>();
    subcategories.add("4654-456465-4564");
    subcategories.add("4654-456465-9512");
    categories.add(subcategories);
    jsonBodyUsingMap.put("categoryIds", categories);

The result of this will be:

{
   "categoryIds":[
      [
         "4654-456465-4564",
         "4654-456465-9512"
      ]
   ],
   "controlStructureId":"4654-456465-4564",
   "controntrolId":"4654-456465-4564",
   "lastUpdate":"1231",
   "vehicleId":"4654-456465-4564"
}