I am using Jersey Client to make a REST service call. Now when I receive the response I want to log the json response and I also want to get the entity populated in my response bean.
Client client = Client.create(config);
ClientResponse cr = client
.resource(endPoint)
.accept("application/json")
.get(ClientResponse.class);
clientResponse.bufferEntity();
String responseToLog = cr.getEntity(String.class);
log.debug(responseToLog);
MyResponseBean myResponse = cr.getEntity(MyResponseBean.class);
Now the problem is that we cannot call the getEntity() two times since the stream gets consumed the first then we cannot use it second time. Hence the above code gives the exception of No content to map to Object due to end of input
. I am sure this is not a very unique requirement and would be common. So what is the best practice or method to do the same?