You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Kyle Sampson <sa...@gmail.com> on 2008/04/29 23:32:45 UTC

ReST/JSON and arrays

I have a simple service with the following method in the service endpoint
interface:

public Collection<String> getNames();

This service is exposed in CXF as a ReST service, returning JSON.  It seems
to work as expected, most of the time.  The collection would be represented
in JSON as, for example: ["name1","name2"].  However, if there's only one
element in the array, the brackets are missing: "name1".  Thus, it looks
like just a scalar value, which confuses the consuming client.

I'm not sure if this is a CXF issue or a problem in Jettison.  There does
seem to be a bug for something like this in the Jettison project: 
http://jira.codehaus.org/browse/JETTISON-22.  However, this seems to have
been fixed in the most recent version of Jettison, and the version included
with the CXF distribution should have the fix.  Anyone else have any idea
why it's doing this?  Thanks.

FYI, I'm using CXF 2.0.5.
-- 
View this message in context: http://www.nabble.com/ReST-JSON-and-arrays-tp16971013p16971013.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: ReST/JSON and arrays

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

On Thu, Mar 3, 2011 at 7:48 PM, jsaenz <jo...@gmail.com> wrote:

> Hi, I'm using CXF 2.3.3 , however, even the conversion to JSON, remove the
> brackets when the list has a single element. There is already a version of
> CXF to solve the problem?
>
>
By default CXF uses Jettison. Please see [1] for the workaround

Cheers, Sergey

[1]
http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-DealingwithJSONarrayserializationissues

Re: ReST/JSON and arrays

Posted by jsaenz <jo...@gmail.com>.
Hi, I'm using CXF 2.3.3 , however, even the conversion to JSON, remove the
brackets when the list has a single element. There is already a version of
CXF to solve the problem?

--
View this message in context: http://cxf.547215.n5.nabble.com/ReST-JSON-and-arrays-tp556871p3408552.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: ReST/JSON and arrays

Posted by Sergey Beryozkin <se...@iona.com>.
Hi

> Kyle Sampson wrote:
>> I have a simple service with the following method in the service endpoint
>> interface:
>>
>> public Collection<String> getNames();
>>
>> This service is exposed in CXF as a ReST service, returning JSON.  It seems
>> to work as expected, most of the time.  The collection would be represented
>> in JSON as, for example: ["name1","name2"].  However, if there's only one
>> element in the array, the brackets are missing: "name1".  Thus, it looks
>> like just a scalar value, which confuses the consuming client.
>>
>> I'm not sure if this is a CXF issue or a problem in Jettison.  There does
>> seem to be a bug for something like this in the Jettison project: http://jira.codehaus.org/browse/JETTISON-22.  However, this 
>> seems to have
>> been fixed in the most recent version of Jettison, and the version included
>> with the CXF distribution should have the fix.  Anyone else have any idea
>> why it's doing this?  Thanks.
>>
>> FYI, I'm using CXF 2.0.5.

Please try jettison-1.1-20080424.080632-3, as recommended by Brice, this issue might've been fixed there already.
CXF currently depends on the 1.0 version of Jettison....


>>
> This issue was recently discussed in the Jersey user group. You can write a custom JAXB context resolver to fix this issue. Please 
> look at [1] for details. But, I am not sure how to implement custom JAXB context resolver in CXF JAX-RS implementation.

Arul, this is part of the 0.7 spec and Kyle is not using JAX-RS at the moment. Hopefully though this specific issue will be fixed at 
the Jettison level.

Cheers, Sergey

>
> [1] http://blogs.sun.com/japod/entry/missing_brackets_at_json_one
>
> Cheers,
> Arul 

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: ReST/JSON and arrays

Posted by Arul Dhesiaseelan <ar...@fluxcorp.com>.
Kyle Sampson wrote:
> I have a simple service with the following method in the service endpoint
> interface:
>
> public Collection<String> getNames();
>
> This service is exposed in CXF as a ReST service, returning JSON.  It seems
> to work as expected, most of the time.  The collection would be represented
> in JSON as, for example: ["name1","name2"].  However, if there's only one
> element in the array, the brackets are missing: "name1".  Thus, it looks
> like just a scalar value, which confuses the consuming client.
>
> I'm not sure if this is a CXF issue or a problem in Jettison.  There does
> seem to be a bug for something like this in the Jettison project: 
> http://jira.codehaus.org/browse/JETTISON-22.  However, this seems to have
> been fixed in the most recent version of Jettison, and the version included
> with the CXF distribution should have the fix.  Anyone else have any idea
> why it's doing this?  Thanks.
>
> FYI, I'm using CXF 2.0.5.
>   
This issue was recently discussed in the Jersey user group. You can 
write a custom JAXB context resolver to fix this issue. Please look at 
[1] for details. But, I am not sure how to implement custom JAXB context 
resolver in CXF JAX-RS implementation.

[1] http://blogs.sun.com/japod/entry/missing_brackets_at_json_one

Cheers,
Arul