Recently at a test, I came across a problem to do some processing after querying the response data from a restful service. I had to write a web service consumer and do some processing using Java.
While I was able to consume the service using Http classes from jdk, I didn't knew of any way to map the response json in their respective pojo's, without using Jackson's or other external mapper libraries.
Now I have been trying to do that. Until now I have tried to change the incoming Json to byte array and deserialize and map into the pojo, but that didn't worked. I remember with JAX-B unmarshalling was possible but it has been carved out of jdk after java 8, and I have been working with higher version JDK 11.
I also tried getting the response as streams but then data processing does not remains equally straightforward, as it would have been in case of working with model classes.
I am in split, any way out of it would be very appreciable ..
HttpRequest req = HttpRequest
.newBuilder(new URI("https://jsonmock.hackerrank.com/api/transactions/search?userId=4"))
.GET().build();
//HttpResponse<byte[]> response = HttpClient.newHttpClient().send(r, BodyHandlers.ofByteArray());
HttpResponse<Stream<String>> response = HttpClient.newHttpClient().send(req, BodyHandlers.ofLines());
Stream<String> responseStream = response.body();