I am trying to test two Rest API Endpoints , one is a get and another is a post. The idea is that the response body returned by the get response shall be the body of the post.
Code that I am using:
RestAssured.baseURI = ROOT_URI;
RequestSpecification httpRequest =
RestAssured.given().header("Authorization", "Basic " + encodedString);
String endPoint="/v1/getworkers";
Response response = httpRequest.request(Method.GET, endPoint);
String responseBody = response.getBody().asString();
Now the response body that I am getting is :
{"workerDetails":
[
{"workerId":"TEST123456",
"securityId":"TESTWORKERID",
"workerStatus":"Active",
"firstName":"Test",
"lastName":"Userone"}
]
}
Now, I do the post request and put the String responseBody as the body:
RestAssured.baseURI = ROOT_URI;
String endpoint="/v1/PostWorkers";
RequestSpecification httpRequest =
RestAssured.given().header("Authorization", "Basic " + encodedString)
.header("Content-Type", "application/json").body(postbody);
Response response = httpRequest.request(Method.POST,endpoint);
String responseBody = response.getBody().asString();
And I am getting the error 400 :
timestamp":1552670194453,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"JSON parse error: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@56bba771
What to do ?