从RESTful Web服务方法返回原始数组 [英] Returning a primitive array from a RESTful web service method

查看:84
本文介绍了从RESTful Web服务方法返回原始数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是REST框架的新手,正在尝试公开一个简单的方法,该方法需要一个整数数组并返回一个Strings数组.但是我对方法中的模仿类型@Produces@Consumes应该是什么感到困惑?以及客户应该如何获得它?

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 ??

我已经看到了使用JAXB通过XML/JSON格式发送复杂对象的方法;但是我还没有看到任何关于基元/数组的代码...有人可以帮忙吗?

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 ?

此外,如果有人也可以显示类似的SOAP服务代码,我将不胜感激...

Plus, I would be grateful if someone can show a similar code for SOAP service also...

谢谢!

PS:我正在Eclipse上使用Jersey/Java来开发服务.

PS : I am using Jersey/Java on Eclipse for developing the services.

推荐答案

原语和数组会自动处理.您不必为他们做任何特别的事情.

Primitives and arrays are handled automatically. You don't have to do anything special for them.

@Produces@Consumes与返回的对象类型无关.它们与服务消费和产生的内容类型有关.它们确实与对象hoever的表示有关.因此,如果您具有@Produces("application/json"),则该框架将使用JSON表示结果.

@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.

您可以浏览 RESTEasy的文档(除了泽西岛,我想您已经看过它了).它几乎全面地涵盖了JAX-RS.

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.

这篇关于从RESTful Web服务方法返回原始数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆