I have used rest assured framework, This is the request body for post method
{
"requestNumber":749 ,
"referenceNumber": "tyryrty",
"cardType": "aliqua pariatur enim cupidatat",
"companyName": "amet Lorem",
"rejectMessage": "tempor dolor officia",
"contactEmail": "mollit pariatur veniam sed",
"serviceProviderEmailList": [
"ipsum nis",
"Ut dolore aliqua exercitation irure"
],
"approvedBy": "sup",
"approvedDate": "1962-07-15T01:00:55.437Z"
}
I have tried in this way but i’m not getting result
JSONObject jsonobj1 = new JSONObject();
jsonobj1.put("requestNumber", 749 );
jsonobj1.put("referenceNumber", "tyryrty");
jsonobj1.put("cardType", "aliqua pariatur enim cupidatat");
jsonobj1.put("companyName", "amet Lorem");
jsonobj1.put("contactEmail", "tempor dolor officia");
Map<String, Object> map= new HashMap<String,Object>();
map.put("serviceProviderEmailList", "ipsum nis");
List<Map<String, Object>> test=Arrays.asList(map);
jsonobj1.put("serviceProviderEmailList", test);
jsonobj1.put("approvedBy", "sup");
jsonobj1.put("approvedDate", "1962-07-15T01:00:55.437Z");
>Solution :
serviceProviderEmailList field is an array of strings, but you are trying to add a single string value to it using a map. Instead, you should create a list of strings and add it to the JSON object as follows:
List<String> serviceProviderEmailList = Arrays.asList("ipsum nis", "Ut dolore aliqua exercitation irure");
jsonobj1.put("serviceProviderEmailList", serviceProviderEmailList);
jsonobj1.put("rejectMessage", "tempor dolor officia");
you can use the body method of the RequestSpecification class to set the request body of a POST request, as follows:
given().contentType("application/json")
.body(jsonobj1.toString())
.when().post("http://your-api-endpoint.com/")
.then().statusCode(200);