Returning a primitive array from a RESTful web ser

2019-08-13 19:44发布

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.

1条回答
戒情不戒烟
2楼-- · 2019-08-13 19:54

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.

查看更多
登录 后发表回答