如何发布字符串与新泽西数组

编程入门 行业动态 更新时间:2024-10-26 04:29:12
本文介绍了如何发布字符串与新泽西数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要发 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
  • 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("a.cz").type(MediaType.APPLICATION_JSON_TYPE).post(array);

更多推荐

如何发布字符串与新泽西数组

本文发布于:2023-10-11 13:48:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1481871.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:新泽西   数组   字符串

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!