tag:blogger.com,1999:blog-785895453418216075.post6048675660277521376..comments2023-08-23T09:18:07.636-07:00Comments on Tug's Blog: JAX-RS: Jersey and JSON single element arraysTug Grallhttp://www.blogger.com/profile/12028480831632266604noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-785895453418216075.post-70908579589952008572017-01-18T02:21:20.834-08:002017-01-18T02:21:20.834-08:00Your Git is 6 years old, but still helped me today...Your Git is 6 years old, but still helped me today ! Thank you very much ! :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-785895453418216075.post-16674801332971235822014-12-16T03:29:11.925-08:002014-12-16T03:29:11.925-08:00Hi, I have a RestFul Webservice which consumes JSO...Hi, I have a RestFul Webservice which consumes JSON and produces JSON. Here i have XMLAttributes which where prefixed with @. I came accross "attributeAsElement" in "com.sun.jersey.api.json.JSONConfiguration" I don't know how to use "attributeAsElement" in my code to produce JSON response without @ for attributes.<br />An example with endpoint would be helpful to understandarunhttps://www.blogger.com/profile/12317243090906303596noreply@blogger.comtag:blogger.com,1999:blog-785895453418216075.post-44864912783689085982014-04-02T03:01:20.714-07:002014-04-02T03:01:20.714-07:00I am pretty desperate about this and I really don&...I am pretty desperate about this and I really don't understand why it is not working.<br />I have followed your netbeans project all the way but my implementation fails when displaying the result.<br />I still don't get any kind of array name like "employee" and the jaxbcontextresolver doesn't seem to have any effect. Please helpAnonymoushttps://www.blogger.com/profile/02259750874456109066noreply@blogger.comtag:blogger.com,1999:blog-785895453418216075.post-87638303245335104722013-04-22T05:36:40.716-07:002013-04-22T05:36:40.716-07:00Thank you :)Thank you :)jersey bolahttp://www.jersey-bola.netnoreply@blogger.comtag:blogger.com,1999:blog-785895453418216075.post-72154569469012306332012-03-08T01:30:01.001-08:002012-03-08T01:30:01.001-08:00Another less intrusive solution is to change the J...Another less intrusive solution is to change the JSON implementation to Jackson:<br /><br />http://stackoverflow.com/questions/5641430/jaxb-single-element-in-arrayAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-785895453418216075.post-16955773242766276972011-11-20T07:26:23.583-08:002011-11-20T07:26:23.583-08:00Dom
I do use this syntax to in some of my code.
...Dom<br /><br />I do use this syntax to in some of my code. <br /><br />Blaise,<br /><br />Thanks for your links<br /><br /><br />TugTug Grallhttps://www.blogger.com/profile/12028480831632266604noreply@blogger.comtag:blogger.com,1999:blog-785895453418216075.post-17433032897570532582011-09-14T14:00:07.946-07:002011-09-14T14:00:07.946-07:00Hello,
The issue you are seeing is due to how the...Hello,<br /><br />The issue you are seeing is due to how the default JSON binding is being implemented. The JAXB impl is reporting StAX events to Jettison which is producing JSON. When an element name is reported once it assumes that it is not a JSON array:<br />- <a href="http://blog.bdoughan.com/2011/04/jaxb-and-json-via-jettison.html" rel="nofollow">JAXB and JSON via Jettison </a><br /><br />You may be interested in the JSON binding being added to <a href="http://www.eclipse.org/eclipselink/moxy.php" rel="nofollow">EclipseLink JAXB (MOXy)</a>:<br />- <a href="http://blog.bdoughan.com/2011/08/json-binding-with-eclipselink-moxy.html" rel="nofollow">JSON Binding with EclipseLink MOXy - Twitter Example</a><br />- <a href="http://blog.bdoughan.com/2011/08/binding-to-json-xml-geocode-example.html" rel="nofollow">Binding to JSON & XML - Geocode Example</a><br /><br />MOXy integrates very easily with the JAX-RS implementation (Jersey) in GlassFish:<br />- <a href="http://bdoughan.blogspot.com/2010/08/creating-restful-web-service-part-35.html" rel="nofollow">Creating a RESTful Web Service - Part 3</a><br />- <a href="http://blog.bdoughan.com/2011/04/moxys-xml-metadata-in-jax-rs-service.html" rel="nofollow">MOXy's XML Metadata in a JAX-RS Service</a><br /><br />-BlaiseBlaise Doughanhttps://www.blogger.com/profile/02016807982653343777noreply@blogger.comtag:blogger.com,1999:blog-785895453418216075.post-65999196756988531352011-09-06T10:09:35.240-07:002011-09-06T10:09:35.240-07:00IMHO, it's more "JSON' to publish the...IMHO, it's more "JSON' to publish the array without the encapsulating object.<br /><br /><b>context = new JSONJAXBContext(JSONConfiguration.natural().build(), supportedTypes);</b><br /><br />With <b>supportedTypes</b> being a collection of Classes to handle:<br /><br /><b>static protected Class[] supportedTypes = {<br /> Employee.class,<br /> // etc.<br />};</b><br /><br />Additional bonus: you don't have singular label for a collection that should be introduced by a plural term ;)<br /><br />A+, DomDom Derrienhttps://www.blogger.com/profile/15197441189507302313noreply@blogger.com