1
votes

I am writing a REST client for my REST webservice using apache httpclient (4.x). I am using JAXB (JSON) for the request/response. In one of my webservice, I have a PUT request in which I have send the JSON request which is represented as the JAXB object. I know I have to use any implementation class of HttpEntity. One of the way I can think of is marshalling the JAXB object to json & use StringEntity. Is there any other way of doing it?

Thanks, Deepesh

1

1 Answers

3
votes

The best way to ensure most efficient content generation with HttpClient is to create a custom HttpEntity implementation. You can leave HttpEntity#getContent unimplemented and only provide HttpEntity#writeTo(OutputStream) method, inside which you can write out your JAXB object using JAXB object serialization facilities.