从 RESTful Web 服务方法返回原始数组
我是 REST 框架的新手,正在尝试公开一个简单的方法,该方法需要一个整数数组并返回一个字符串数组。但我很困惑该方法的 mimetype @Produces
和 @Consumes
应该是什么?客户应该如何获得它?
我已经看到了使用 JAXB 通过 XML/JSON 格式发送复杂对象的方法;但我还没有看到任何原语/数组的代码......有人可以帮忙吗?
另外,如果有人也可以展示 SOAP 服务的类似代码,我将不胜感激...
谢谢!
PS:我在 Eclipse 上使用 Jersey/Java 来开发服务。
I am new to the REST framework, and am trying to expose a simple method which requires an array of integers and returns an array of Strings. But I am confused as to what mimetype @Produces
and @Consumes
on the method should be ? And how should the client get it ??
I have seen ways to use JAXB for sending a complex object via XML/JSON formats ; but I have yet not seen any code for primitives / arrays...can someone please help ?
Plus, I would be grateful if someone can show a similar code for SOAP service also...
Thanks !
PS : I am using Jersey/Java on Eclipse for developing the services.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基元和数组是自动处理的。你不需要为他们做任何特别的事情。
@Produces
和@Consumes
与返回的对象类型无关。它们与服务消费和生成的内容类型有关。然而,它们确实与对象的表示有关。因此,如果您有 @Produces("application/json"),那么框架将使用 JSON 来表示结果。您可以查看 RESTEasy(除了泽西岛,我猜你已经看过了)。它几乎全面地涵盖了 JAX-RS。
Primitives and arrays are handled automatically. You don't have to do anything special for them.
@Produces
and@Consumes
are not about the type of object returned. They are about the content type which the service consumes and produces. They do relate to the representation of the object hoever. So if you have@Produces("application/json")
, then the framework will use JSON to represent to result.You can look through the documentation of RESTEasy (in addition to that of Jersey, which I guess you've looked through already). It pretty much covers JAX-RS in a comprehensive manner.