Super. Actually I think I've fixed it yesterday - but I don't have a system test yet so I will use your sample for it.
To make things working properly in CXF JAXRS one will need to explicitly register a JSONProvider and just set a 'serializeAsArray' property to 'true' - may be it even has to be a default property, I'm not sure. No Context providers will be needed. Jettison does have it fixed - it was just that our provider did not know about it. Will be merged to the trunk soon Many thanks for helping with solving this issue. Cheers, Sergey -----Original Message----- From: Maleldil [mailto:[EMAIL PROTECTED] Sent: 26 November 2008 20:54 To: [email protected] Subject: Re: Lists containing one object are not serialized as JSON arrays Sure thing. Here's my classes simplified: @XmlRootElement(name = "result") @XmlAccessorType(XmlAccessType.FIELD) public class Result { private List<TagVO> tags; // assume getters/setters } @XmlAccessorType(XmlAccessType.FIELD) public class TagVO { private String name; private String group; // assume getters/setters } And my JAX-RS service class: @Path("/resources") public class JsonRestResource() { @GET @Path("/{id}") @Produces("application/json") Response getResource(@PathParam("id") String id) { Result result = new Result(); List<TagVO> tags = new ArrayList<TagVO>(); TagVO tag1 = new TagVO(); tag1.setName("Tag1"); tag1.setGroup("Group1"); tags.add(tag1); TagVO tag2 = new TagVO(); tag2.setName("Tag2"); tag2.setGroup("Group2"); tags.add(tag2); result.setTags(tags); return Response.status(Response.Status.OK).entity(result).build(); } } Let me know if you need any more information. -Geoff Sergey Beryozkin-3 wrote: > > Hi, thanks for posting a link > > Can you please explain me a bit more what you do (I know you have it's all > working with Jersey) - > but I'd to try few things with Jettison > > Here's your original email : > > I have a list called "tags" that contains TagVO objects. A TagVO > simply contains 2 string fields, called "name" and "group". > If I have two or more objects in that list then it is serialized as > follows: > > {tags:[{name: "tag1", group: "group1"},{name: "tag2", group: "group2"}]} > > So far so good. However, if there is only one item, I will get the > following: > > {tags:{name: "tag1", group: "group1"}} > > Which is obviously not correct. > > > S.B. : should it be > > {tags:[{name: "tag1", group: "group1"}]} > > ? > > Is there any chance you can post a very simple code sample showing how > this list of TavVO is used or at least how do TagList and > TagVO look like (like what JAXB annotations they have) ? > > Many thanks > Sergey > > > > > > > > >> >> Sure thing. http://jira.codehaus.org/browse/JETTISON-22 Here is the >> link. >> I mistakenly thought that this was related to >> http://jira.codehaus.org/browse/JETTISON-46 this bug report which is why >> I >> thought the latest version of Jettison would fix it, but the actual bug >> that >> relates to this was supposedly fixed in version 1.0 of Jettison. >> >> >> >> Sergey Beryozkin-3 wrote: >>> >>> Ok, no worries. >>> >>> Can you give me a favour and send a link to a Jettison JIRA which claims >>> to have resolved this bug ? >>> >>> Thanks, Sergey >>> >>>> >>>> The problem is that, upon further inspection, the JSONJAXBContext >>>> parameters >>>> that are specified for the Jersey ContextResolver are only for their >>>> own >>>> Mapped implementation of the JSON provider that doesn't use Jettison, >>>> and >>>> it >>>> doesn't look like there is any way to pass Jettison any settings that >>>> tell >>>> it what to do. So for now my only option is to migrate my application >>>> to >>>> Jersey (which I have done and is working correctly). >>>> >>>> Thank you for all your help. >>>> >>>> >>>> Sergey Beryozkin-2 wrote: >>>>> >>>>> Hi >>>>> >>>>> I missed it was a Jersey specific JSONJAXBContext... >>>>> >>>>> If we knew what JSON/Jettison property passed as a JAXBContext >>>>> property >>>>> would help jettison to make the right decision (similar to the one >>>>> used >>>>> in the Jakob's blog entry) then I guess it would still work pretty >>>>> much >>>>> the same way as suggested there - but I'm not sure if such property >>>>> exists for Jettison. >>>>> >>>>> You can register a custom resolver like this : >>>>> >>>>> <jaxrs:providers> >>>>> <ref bean="jsonProvider"/> >>>>> <bean class="MyContextProvider"/> >>>>> </jaxrs:providers> >>>>> >>>>>> Supposedly this bug is fixed in the latest trunk of jettison, which I >>>>> linked >>>>> to my project, but it still does not work correctly in CXF. >>>>> >>>>> May be debugging can help, if it's feasible and see if it's really >>>>> been >>>>> fixed and if it's really the latest jettison library you expect is >>>>> being >>>>> picked up as opposed to the buggy one (unlikely - but it might happen >>>>> - >>>>> it happens to me anyway now and then :-)) >>>>> >>>>> Cheers, Sergey >>>>> >>>>> >>>> >>>> -- >>>> View this message in context: >>>> http://www.nabble.com/Lists-containing-one-object-are-not-serialized-as- JSON-arrays-tp20613099p20632671.html >>>> Sent from the cxf-user mailing list archive at Nabble.com. >>>> >>>> >>> >>> >>> >>> >> >> -- >> View this message in context: >> http://www.nabble.com/Lists-containing-one-object-are-not-serialized-as- JSON-arrays-tp20613099p20666834.html >> Sent from the cxf-user mailing list archive at Nabble.com. >> >> > > > > -- View this message in context: http://www.nabble.com/Lists-containing-one-object-are-not-serialized-as- JSON-arrays-tp20613099p20708808.html Sent from the cxf-user mailing list archive at Nabble.com.
