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
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"
}
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.