如何发布字符串与新泽西数组 [英] How to POST an Array of String with Jersey

查看:157
本文介绍了如何发布字符串与新泽西数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要发 String数组直接使用类似:

service....post(ClientResponse.class, new String[]{"one","two","three"} );

有一个 的MediaType 可用于检索服务器上的字符串数组?

在我实现我有一个警告提示 的String [] 不是解析为一个具体类型。

In my implementation I have a WARNING saying that String[] is not resolvable to a concrete type.

我怎样才能张贴阵列封装没有到另一个( @XmlRootElement )类?

How can I POST an array without encapsulating it into another (@XmlRootElement) class?

推荐答案

请参阅How在泽西REST Web服务返回数组?(不完全是这样,但相关的)。

See How to return Array in Jersey REST webservice? (not exactly this, but related).

JAX-RS(也不泽西)不支持原始类型,包括字符串返回列表。格式不指定,所以你需要将数据封装成的东西,并使用XML / JSON(我会这么做),也可以实现对任何你希望你的化MessageBodyReader /作家(甚至字符串数组)。参见:

JAX-RS (nor Jersey) does not support returning List of primitive types, including String. Format is not specified, so you'll need to encapsulate your data into something and use XML/JSON (I would do that) OR you can implement your MessageBodyReader/Writer for whatever you want (even array of strings). See:

  • MessageBodyReader
  • MessageBodyWriter

编辑:在客户端JSONArray:

edit: JSONArray on client side:

ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(JSONArrayProvider.App.class);
Client c = Client.create(cc);

JSONArray array = new JSONArray();
array.put(1);
array.put(4);

c.addFilter(new LoggingFilter());
c.resource("http://a.cz").type(MediaType.APPLICATION_JSON_TYPE).post(array);

这篇关于如何发布字符串与新泽西数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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