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 

-----Original Message-----
From: Maleldil [mailto:[EMAIL PROTECTED] 
Sent: 21 November 2008 19:30
To: [email protected]
Subject: Re: Lists containing one object are not serialized as JSON
arrays


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.  XStream had
the
same problem and it required that they make a change in their code to
fix
the issue as well.

Sergey, I can try the ContextResolver suggestion.  However, the example
provided on Jakub's blog seems specific to Jersey (namely the
JAXBContext
that is being used).  Would I need to create a custom JAXBContext as
well? 
Also, how can I configure a custom ContextResolver through Spring and
get
CXF to recognize it?  I'm currently doing the following in my
applicationContext.xml:

    <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
                <entry key="http://cxf.apache.org/bindings/xformat";
value="cxf"/>
                <entry key="http://www.w3.org/2001/XMLSchema-instance";
value="xsi"/>
    </util:map>
    
    <!-- JAX-RS Configuration -->
    <bean id="jsonProvider"
class="org.apache.cxf.jaxrs.provider.JSONProvider">
        <property name="namespaceMap" ref="jsonNamespaceMap"/>
    </bean>

    <jaxrs:server id="restService" address="/">
                <jaxrs:serviceBeans>
                        <ref bean="restServiceClass"/>
                </jaxrs:serviceBeans>
                <jaxrs:providers>
                        <ref bean="jsonProvider"/>
                </jaxrs:providers>
    </jaxrs:server>

The restServiceClass is annotated with Spring's @Service annotation and
spring is configured to auto-scan for that annotation.  Like I said,
everything works fine except for this array issue, so I'm just wondering
how
I would wire a custom ContextResolver into this setup.

Again, I appreciate all your help.



dkulp wrote:
> 
> 
> 
> I believe this is a "bug"/"restriction" in jettison[1] which is the
> library we 
> use for producing json.    I know with 1.1, they are adding some
mapping 
> things to provides ways to specify how things are written out.   No
idea
> when 
> 1.1 will be released though.   
> 
> Dan
> 
> [1] http://jettison.codehaus.org
> 
> 
> On Thursday 20 November 2008 7:49:18 pm Maleldil wrote:
>> I am using JAX-RS and CXF 2.1.3.  I have value objects that model my
JSON
>> schemas and usually everything works great.  The problem is that I
when a
>> list of objects only contains one item then the resulting JSON is not
>> serialized as an array, but as an object.  Example:
>>
>> 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.
>>
>> I've found a few mentions of this issue in CXF but with no solutions.
>> Jersey has the same issue but I found a blog article that explains
how to
>> fix it in their framework (
>> http://blogs.sun.com/japod/entry/missing_brackets_at_json_one see
here ).
>> Is there anything that can be done about this in CXF though?  This is
>> really a showstopper for our project and needs to be resolved, and
seems
>> like a major issue in general.
>>
>> Any help would be appreciated.
> 
> 
> 
> -- 
> Daniel Kulp
> [EMAIL PROTECTED]
> http://dankulp.com/blog
> 
> 

-- 
View this message in context:
http://www.nabble.com/Lists-containing-one-object-are-not-serialized-as-
JSON-arrays-tp20613099p20628103.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to