Below is my Request,
[
{
"userId": "value1"
},{
"userId": "value2"
}
]
I tried creating POJO class and build the request and also used ArrayList but something wrong in request body
CodePudding user response:
You can't do List<User>.class so try using ParameterizedTypeReference
CodePudding user response:
Found answer for the below Request,
API request body,
[
{
"userId": "value1"
},{
"userId": "value2"
}
]
Solution :
public String sendingRequest(String uid, String uid1){
JSONObject user1 = new JSONObject();
user1.put("userId", uid);
JSONObject user2 = new JSONObject();
user2.put("userId", uid1);
JSONArray jsonArray = new JSONArray();
jsonArray.put(user1);
jsonArray.put(user2);
String jsonStr = jsonArray.toString();
System.out.println("jsonString: " jsonStr);
return jsonStr;
}
Outcome:
[{"userId":"ljtdmm"},{"userId":"BBLSHl"}]
