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

Reply via email to