简体   繁体   English

JAXB和HttpEntity

[英]JAXB & HttpEntity

I am writing a REST client for my REST webservice using apache httpclient (4.x). 我正在使用apache httpclient(4.x)为我的REST Web服务编写REST客户端。 I am using JAXB (JSON) for the request/response. 我正在使用JAXB(JSON)来请求/响应。 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. 在我的一个web服务中,我有一个PUT请求,其中我发送了JSON请求,该请求表示为JAXB对象。 I know I have to use any implementation class of HttpEntity. 我知道我必须使用HttpEntity的任何实现类。 One of the way I can think of is marshalling the JAXB object to json & use StringEntity. 我能想到的一种方法是将JAXB对象编组为json并使用StringEntity。 Is there any other way of doing it? 这样做还有其他办法吗?

Thanks, Deepesh 谢谢,Deepesh

The best way to ensure most efficient content generation with HttpClient is to create a custom HttpEntity implementation. 使用HttpClient确保最有效内容生成的最佳方法是创建自定义HttpEntity实现。 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. 您可以让HttpEntity#getContent未实现,只提供HttpEntity#writeTo(OutputStream)方法,您可以在其中使用JAXB对象序列化工具写出JAXB对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM