For API testing I have to parse the response of a request using io.micronaut.http.client.HttpClient
I prefer to use the format given below.
Response<User> response =
client.toBlocking().retrieve(HttpRequest.POST("/", user), Response.class);
But It is not working. I am getting type cast error while trying to fetch User from response
User user = response.getUser();
Currently I am using ObjectMapper (Jackson) like given below,
String response = client.toBlocking().retrieve(HttpRequest.POST("/", user), String.class);
ObjectMapper objectMapper = new ObjectMapper();
Response<User> response = objectMapper.readValue(response, new TypeReference<Response<User>>() {});
Is there any way to use TypeReference directly with HttpClient retrieve method? Or any other way to use generic class type with HttpClient.
Other useful informations
// Response generic class
class Response<T> {
T data;
....
}
Sample response
{
"data": {
"name":"sample"
},
"message": "Success"
}