You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Ricardo <ri...@intervisit.com> on 2013/03/14 15:35:45 UTC

json list returning one element lacks square bracket pair

Hi, this related to an anwer I got on a question I asked on a general Java
forum: 

http://stackoverflow.com/questions/15404528/jaxb-list-with-one-element

Anyone recognizes this with TomEE 1.5.1 out-of-the-box ? Seems - well, that
is my first and quick conclusion - that TomEE is not using a JAXB
implementation that adheres to the standard completely. 

What to do? I like the auto-discovery modus of TomEE, and I am not really
ready yet for adding an extra property file, and/or adding extra jars to my
installation.  Thanx in advance. 







--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
Romain,

Thanks for your inspiring posts on this subject.

Appreciated. 

Ric.



--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661617.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Romain Manni-Bucau <rm...@gmail.com>.
http://cxf.apache.org/docs/jax-rs-data-bindings.html

all is explained here

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/18 Ricardo <ri...@intervisit.com>

> Got any experience with the 'arrayKeys' property?  Well I do now
>
> For now, I just forget about why Jackson is not provisioned in the way as
> described earlier (assignment for next week).
>
> I found out that the following is fit for my needs:
>
> File: resources.xml:
>
> <resources>
>
>         <Service id="json"
> class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>     serializeAsArray = true
>     dropRootElement = false
>     arrayKeys = list-of-objects
>     supportUnwrapped = true
>         </Service>
>
> </resources>
>
> File: openejb-jar.xml:
>
> <?xml version="1.0"?>
> <openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">
>
>         <pojo-deployment class-name="simple.Producer">
>   <properties>
>       cxf.jaxrs.providers = json
>   </properties>
>         </pojo-deployment>
>
> </openejb-jar>
>
> The resulting JSON is now:
> {"json-response":{"number":1,"list-of-objects":[{"one":100,"two":200}]}}
>
> Exactly what I need :-)
>
> Funnily enough, the [] pair of the toplevel element has vanished now. When
> I
> add it to the arrayKeys property (as in: arrayKeys = list-of-objects,
> json-response), the resulting JSON is:
>
> {"json-response":[{"number":1,"list-of-objects":[{"one":100,"two":200}]}]}
>
> A moment for reflection. Many years ago I had a computer architecture
> teacher (in fact Prof. Dr. Gerrit Blaauw, one of the principal designers of
> the IBM System/360 line of computers, together with Fred Brooks, Gene
> Amdahl, and others), who teached me many interesting and important things.
> I
> think what he taught me about "orthogonality", has not lost any importance
> in this day and age.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661615.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
Got any experience with the 'arrayKeys' property?  Well I do now

For now, I just forget about why Jackson is not provisioned in the way as
described earlier (assignment for next week).

I found out that the following is fit for my needs:

File: resources.xml:

<resources>

        <Service id="json"
class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
    serializeAsArray = true
    dropRootElement = false
    arrayKeys = list-of-objects
    supportUnwrapped = true
        </Service>

</resources>

File: openejb-jar.xml:

<?xml version="1.0"?>
<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">

        <pojo-deployment class-name="simple.Producer">
  <properties>
      cxf.jaxrs.providers = json
  </properties>
        </pojo-deployment> 

</openejb-jar>

The resulting JSON is now:
{"json-response":{"number":1,"list-of-objects":[{"one":100,"two":200}]}}

Exactly what I need :-)

Funnily enough, the [] pair of the toplevel element has vanished now. When I
add it to the arrayKeys property (as in: arrayKeys = list-of-objects,
json-response), the resulting JSON is:

{"json-response":[{"number":1,"list-of-objects":[{"one":100,"two":200}]}]}

A moment for reflection. Many years ago I had a computer architecture
teacher (in fact Prof. Dr. Gerrit Blaauw, one of the principal designers of
the IBM System/360 line of computers, together with Fred Brooks, Gene
Amdahl, and others), who teached me many interesting and important things. I
think what he taught me about "orthogonality", has not lost any importance
in this day and age. 



--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661615.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Romain Manni-Bucau <rm...@gmail.com>.
cxf.jaxrs.provider (not cxf.jax-rs.provider)

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/18 Ricardo <ri...@intervisit.com>

> Got any experience with 'arrayKeys' ???
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661611.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
Got any experience with 'arrayKeys' ???



--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661611.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
Well, 160 snapshot gives exact the same, and I think the Jackson
implementation should have been at work:

{"json-response":{"number":1,"list-of-objects":{"one":100,"two":200}}}

But...my friend...what am I testing now? 

Feels I am still getting JSON from the standard provider. 



--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661610.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Romain Manni-Bucau <rm...@gmail.com>.
this branch uses some cxf jsonprovider config:
https://github.com/rmannibucau/JeBlog/blob/rest/src/main/webapp/WEB-INF/openejb-jar.xml
 and
https://github.com/rmannibucau/JeBlog/blob/rest/src/main/webapp/WEB-INF/resources.xml

and i'm sure it is taken into account, what i mean is maybe you hit a bug
and i would like to be sure it is not already fixed on 1.6.0.

jackson change should be pretty obvious but you can test with cxf
jsonprovider too

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/18 Ricardo <ri...@intervisit.com>

> You mean...as is from Github, with the Jackson replacement ?
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661606.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
You mean...as is from Github, with the Jackson replacement ?



--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661606.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Can you give a try with the snapshot (1.6.0-SNAPSHOT)

wonder if the default providers were not added by default too in previous
version so you don't know which one of both providers were used

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/18 Ricardo <ri...@intervisit.com>

> Yeah, a wrong filename, I need new glasses seems :-D
>
> But...not that it helps, I still get the old-style bracket less output for
> a
> list with one item :-(
>
>
> Apropo.  Interesting, the code for the @Provider, but I am really trying to
> understand the declarative way with xml files now :-P   If you got any
> other
> ideas about that, appreciated.
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661604.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
Yeah, a wrong filename, I need new glasses seems :-D

But...not that it helps, I still get the old-style bracket less output for a
list with one item :-( 


Apropo.  Interesting, the code for the @Provider, but I am really trying to
understand the declarative way with xml files now :-P   If you got any other
ideas about that, appreciated. 





--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661604.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Romain Manni-Bucau <rm...@gmail.com>.
think it is logged in debug (would need to check btw)

FYI on tomee trunk (think it can be the same for 1.5.1) i'm using:

src/main/webapp/WEB-INF/*
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
  <interceptors>

<class>net.atos.cloud.server.security.api.interceptor.AuthenticatedInterceptor</class>
  </interceptors>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">
  <pojo-deployment class-name="org.superbiz.MyApplication">
    <properties>
      # we use jackson as provider since it is far easier to use than
jettison (default one)
      # and doesn't have complicated issues to work around (like url
escaping)
      cxf.jaxrs.providers = org.superbiz.provider.JSonProvider
    </properties>
  </pojo-deployment>
</openejb-jar>

and here is the provider:

@Provider
public class JSonProvider implements MessageBodyReader<Object>,
MessageBodyWriter<Object> {
    private final JacksonJsonProvider delegate;

    public JSonProvider() {
        delegate = new JacksonJsonProvider(null, Annotations.JAXB);
        delegate.locateMapper(Info.class, MediaType.APPLICATION_JSON_TYPE)
                .setSerializationInclusion(JsonInclude.Include.NON_NULL);
    }

    @Override
    public boolean isReadable(final Class<?> aClass, final Type type, final
Annotation[] annotations, final MediaType mediaType) {
        return delegate.isReadable(aClass, type, annotations, mediaType);
    }

    @Override
    public Object readFrom(final Class<Object> objectClass, final Type
type, final Annotation[] annotations,
                           final MediaType mediaType, final
MultivaluedMap<String, String> stringStringMultivaluedMap, final
InputStream inputStream) throws IOException {
        return delegate.readFrom(objectClass, type, annotations, mediaType,
stringStringMultivaluedMap, inputStream);
    }

    @Override
    public long getSize(final Object o, final Class<?> aClass, final Type
type,
                        final Annotation[] annotations, final MediaType
mediaType) {
        return delegate.getSize(o, aClass, type, annotations, mediaType);
    }

    @Override
    public boolean isWriteable(final Class<?> aClass, final Type type,
                               final Annotation[] annotations, final
MediaType mediaType) {
        return delegate.isWriteable(aClass, type, annotations, mediaType);
    }

    @Override
    public void writeTo(final Object o, final Class<?> aClass, final Type
type, final Annotation[] annotations,
                        final MediaType mediaType, final
MultivaluedMap<String, Object> stringObjectMultivaluedMap, final
OutputStream outputStream) throws IOException {
        delegate.writeTo(o, aClass, type, annotations, mediaType,
stringObjectMultivaluedMap, outputStream);
    }
}


*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/18 James Green <ja...@gmail.com>

> At this point logging which config files were found on a per archive basis
> always becomes useful. If this is possible, might be making the
> documentation more "known".
>
>
>
> On 18 March 2013 17:32, Romain Manni-Bucau <rm...@gmail.com> wrote:
>
> > openjb-jar.xml and not openejb-jar.xml?
> >
> > *Romain Manni-Bucau*
> > *Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
> > *Blog: **http://rmannibucau.wordpress.com/*<
> > http://rmannibucau.wordpress.com/>
> > *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
> > *Github: https://github.com/rmannibucau*
> >
> >
> >
> > 2013/3/18 Ricardo <ri...@intervisit.com>
> >
> > > Sure. https://github.com/ricardogithub/tomeejackson
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > >
> >
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661600.html
> > > Sent from the OpenEJB User mailing list archive at Nabble.com.
> > >
> >
>

Re: json list returning one element lacks square bracket pair

Posted by James Green <ja...@gmail.com>.
At this point logging which config files were found on a per archive basis
always becomes useful. If this is possible, might be making the
documentation more "known".



On 18 March 2013 17:32, Romain Manni-Bucau <rm...@gmail.com> wrote:

> openjb-jar.xml and not openejb-jar.xml?
>
> *Romain Manni-Bucau*
> *Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
> *Blog: **http://rmannibucau.wordpress.com/*<
> http://rmannibucau.wordpress.com/>
> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
> *Github: https://github.com/rmannibucau*
>
>
>
> 2013/3/18 Ricardo <ri...@intervisit.com>
>
> > Sure. https://github.com/ricardogithub/tomeejackson
> >
> >
> >
> > --
> > View this message in context:
> >
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661600.html
> > Sent from the OpenEJB User mailing list archive at Nabble.com.
> >
>

Re: json list returning one element lacks square bracket pair

Posted by Romain Manni-Bucau <rm...@gmail.com>.
openjb-jar.xml and not openejb-jar.xml?

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/18 Ricardo <ri...@intervisit.com>

> Sure. https://github.com/ricardogithub/tomeejackson
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661600.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
Sure. https://github.com/ricardogithub/tomeejackson



--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661600.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Romain Manni-Bucau <rm...@gmail.com>.
can you reproduce it in a simple webapp?



*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/18 Ricardo <ri...@intervisit.com>

> Since Jackson seems to be superior when it comes to Lists and
> configuration,
> I gave it a try:
>
> What I read on this forum is, that I need two things:
> a) two Services defined in the resources.xml file:
> <resources>
>     <Service id="jsonProvider"
> class-name="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
>     <Service id="jaxbProvider"
> class-name="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" />
> </resources>
>
> and b) for each POJO that I want to marshal using Jackon, a deployment
> definition in openejb-jar.xml:
>
>     <pojo-deployment class-name="simple.Producer">
>         <properties>
>             cxf.jax-rs.providers = jsonProvider, jaxbProvider
>         </properties>
>     </pojo-deployment>
>
> and c) put jackson-all-1.9.11.jar in the WebContent/WEB-INF/lib directory.
>
> I did all these three steps, and the application will produce JSON.
>
> How do I know that Jackson is the marshaller (since i still get the CXF
> style non-list form of a single List element)?
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661598.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
Since Jackson seems to be superior when it comes to Lists and configuration,
I gave it a try: 

What I read on this forum is, that I need two things: 
a) two Services defined in the resources.xml file: 
<resources>
    <Service id="jsonProvider"
class-name="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
    <Service id="jaxbProvider"
class-name="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" />
</resources>

and b) for each POJO that I want to marshal using Jackon, a deployment
definition in openejb-jar.xml:

    <pojo-deployment class-name="simple.Producer">    
        <properties>
            cxf.jax-rs.providers = jsonProvider, jaxbProvider
        </properties>       
    </pojo-deployment>

and c) put jackson-all-1.9.11.jar in the WebContent/WEB-INF/lib directory. 

I did all these three steps, and the application will produce JSON. 

How do I know that Jackson is the marshaller (since i still get the CXF
style non-list form of a single List element)?





--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661598.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
Yeah... ur right, here is the openejb-jar.xml:

<?xml version="1.0"?>
<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">

	<pojo-deployment class-name="simple.Producer">
  		<properties>
      		cxf.jaxrs.providers = json-Producer
  		</properties>
	</pojo-deployment> 

	<pojo-deployment class-name="simple.ContainerObject">
  		<properties>
      		cxf.jaxrs.providers = json-ContainerObject
  		</properties>
	</pojo-deployment> 

	<pojo-deployment class-name="simple.EmbeddedObject">
  		<properties>
      		cxf.jaxrs.providers = json-EmbeddedObject
  		</properties>
	</pojo-deployment> 

</openejb-jar>

And to be complete again, resources.xml again: 

<resources>

	<Service id="json-Producer"
class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
    	serializeAsArray = true
    	supportUnwrapped = true
	</Service>

	<Service id="json-ContainerObject"
class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
    	serializeAsArray = true
	   	supportUnwrapped = true
	</Service>

	<Service id="json-EmbeddedObject"
class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
    	serializeAsArray = true
    	supportUnwrapped = true   	
	</Service>

</resources>



--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661596.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Romain Manni-Bucau <rm...@gmail.com>.
hmm,

wrong copy/paste? the openejb-jar.xml is your resources.xml

there are more attribute in cxf json provider and i recall it to not be
very friendly to configure. personally i use jackson which is trivial to
use, maybe ask cxf list to get the right config of such a json provider
(even in programmatic or spring way) then we can help you to get it in
tomee.

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/18 Ricardo <ri...@intervisit.com>

> I have a little progress now, finally (I missed your "mea culpa" about
> <Service/> in the link you referred to).
>
> I have three POJO's, 1) my Producer REST service class, 2) a container
> object, and 3) an embedded object that is defined as a List<> element in
> the
> container object.
>
> When I define the following in openejb-jar.xml:
>
> <resources>
>
>         <Service id="json-Producer"
> class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>         serializeAsArray = true
>         supportUnwrapped = true
>         </Service>
>
>         <Resource id="json-ContainerObject"
> class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>         serializeAsArray = true
>                 supportUnwrapped = true
>         </Resource>
>
>         <Resource id="json-EmbeddedObject"
> class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>         serializeAsArray = true
>         supportUnwrapped = true
>         </Resource>
>
> </resources>
>
> and the following in tresources.xml:
>
> <resources>
>
>         <Service id="json-Producer"
> class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>         serializeAsArray = true
>         supportUnwrapped = true
>         </Service>
>
>         <Resource id="json-ContainerObject"
> class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>         serializeAsArray = true
>                 supportUnwrapped = true
>         </Resource>
>
>         <Resource id="json-EmbeddedObject"
> class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>         serializeAsArray = true
>         supportUnwrapped = true
>         </Resource>
>
> </resources>
>
> The nett effect is:
>
> {"json-response":[{"number":1,"list-of-objects":{"one":100,"two":200}}]}
>
> My observations so far:
> 1) the JSON response at the top level is indeed serialzed as an array;
> 2) i had expected to see the [] brackets around the values of the
> list-of-objects attribute as well, but that is not happening.
>
> Any idea what I am missing now?
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661594.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
I have a little progress now, finally (I missed your "mea culpa" about
<Service/> in the link you referred to). 

I have three POJO's, 1) my Producer REST service class, 2) a container
object, and 3) an embedded object that is defined as a List<> element in the
container object.

When I define the following in openejb-jar.xml: 

<resources>

	<Service id="json-Producer"
class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
    	serializeAsArray = true
    	supportUnwrapped = true
	</Service>

	<Resource id="json-ContainerObject"
class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
    	serializeAsArray = true
	   	supportUnwrapped = true
	</Resource>

	<Resource id="json-EmbeddedObject"
class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
    	serializeAsArray = true
    	supportUnwrapped = true    	
	</Resource>

</resources>

and the following in tresources.xml: 

<resources>

	<Service id="json-Producer"
class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
    	serializeAsArray = true
    	supportUnwrapped = true
	</Service>

	<Resource id="json-ContainerObject"
class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
    	serializeAsArray = true
	   	supportUnwrapped = true
	</Resource>

	<Resource id="json-EmbeddedObject"
class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
    	serializeAsArray = true
    	supportUnwrapped = true    	
	</Resource>

</resources>

The nett effect is: 

{"json-response":[{"number":1,"list-of-objects":{"one":100,"two":200}}]}

My observations so far: 
1) the JSON response at the top level is indeed serialzed as an array; 
2) i had expected to see the [] brackets around the values of the
list-of-objects attribute as well, but that is not happening. 

Any idea what I am missing now? 



--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661594.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Romain Manni-Bucau <rm...@gmail.com>.
you are doing weird spring here

see
http://openejb.979440.n4.nabble.com/Configuring-Apache-CXF-in-TomEE-td4660207.html,
i think it contain main information

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/15 Ricardo <ri...@intervisit.com>

> Thx, let me have a go at the resources.xml first
>
> Something like this I came up with (but I don't get it loaded, nor any
> special message on the console :
>
> <resources>
> <beans>
> <jaxrs:server id="producer" address="/">
>     <jaxrs:serviceBeans>
>       <bean class="simple.Producer" />
>     </jaxrs:serviceBeans>
>
>     <jaxrs:providers>
>       <ref bean="jsonProvider" />
>     </jaxrs:providers>
>
>     <bean id="jsonProvider"
> class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
>       <property name="serializeAsArray" value="true"/>
>     </bean>
> </jaxrs:server>
> </beans>
> </resources>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661538.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
Thx, let me have a go at the resources.xml first 

Something like this I came up with (but I don't get it loaded, nor any
special message on the console :

<resources>
<beans>
<jaxrs:server id="producer" address="/">
    <jaxrs:serviceBeans>
      <bean class="simple.Producer" />
    </jaxrs:serviceBeans>

    <jaxrs:providers>
      <ref bean="jsonProvider" />
    </jaxrs:providers>

    <bean id="jsonProvider"
class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
      <property name="serializeAsArray" value="true"/>
    </bean>
</jaxrs:server>
</beans>
</resources>




--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661538.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Romain Manni-Bucau <rm...@gmail.com>.
you can do your own @Provider but just configuring a jsonprovider in
resources.xml should work too

personally i like to wrap providers in a custom pojo i can totally handle
by programmation because it really eases config discovery (completion) +
helps with upgrades (api changes)

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/15 Ricardo <ri...@intervisit.com>

> Understand. Maybe you can give a bit more hints about how to fix it in my
> application program.
>
> Do you mean 1) explicitly adding a @Provider class, or 2) fiddling with
> some
> xml resources?
>
> Thankx in advance.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661536.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
Understand. Maybe you can give a bit more hints about how to fix it in my
application program. 

Do you mean 1) explicitly adding a @Provider class, or 2) fiddling with some
xml resources?

Thankx in advance.



--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661536.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Romain Manni-Bucau <rm...@gmail.com>.
we speak about the same thing

the point is the following: if serializae as array is set to true all
object will be considered as array by default (was the case before), we
removed it and now fo object (not list) it is fine.

But you have the list issue. So basically you have to configure the json
provider to serialize list as array "always". I think the conf is on the
forum (i can't recall it)

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/15 Ricardo <ri...@intervisit.com>

> Thanks for your responses, but I think we are not talking about the same
> thing. When I use REST to produce JSON (out of the box in TomEE+ 1.5.1), I
> really am able to reproduce the situation, e.g.
>
> Wrong for one list member:
>  {"myObject":{"number":1,"anotherObjectList":{"one":100,"two":200}}}
>
> Good for two list members:
>
> {"myObject":{"number":1,"anotherObjectList":[{"one":100,"two":200},{"one":300,"two":400}]}}
>
> So, any more ideas? Thx in advance.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661533.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
Thanks for your responses, but I think we are not talking about the same
thing. When I use REST to produce JSON (out of the box in TomEE+ 1.5.1), I
really am able to reproduce the situation, e.g. 

Wrong for one list member:
 {"myObject":{"number":1,"anotherObjectList":{"one":100,"two":200}}} 

Good for two list members:
{"myObject":{"number":1,"anotherObjectList":[{"one":100,"two":200},{"one":300,"two":400}]}}

So, any more ideas? Thx in advance.



--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661533.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Romain Manni-Bucau <rm...@gmail.com>.
yes,

here is the code:

        final JSONProvider json = new JSONProvider();
        // TOMEE-514
        // json.setSerializeAsArray(true);


with the jsonprovider the one of cxf:
org.apache.cxf.jaxrs.provider.json.JSONProvider


*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/14 Ricardo <ri...@intervisit.com>

> Are you sure the change made it properly into the 1.5.1 production
> delivery?
>
> To be clear: on my 1.5.1 installation, lists with one element are JSON
> produced without the square bracket-pair.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661526.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: json list returning one element lacks square bracket pair

Posted by Ricardo <ri...@intervisit.com>.
Are you sure the change made it properly into the 1.5.1 production delivery? 

To be clear: on my 1.5.1 installation, lists with one element are JSON
produced without the square bracket-pair. 



--
View this message in context: http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524p4661526.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: json list returning one element lacks square bracket pair

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,

it should since it has been fixed here
https://issues.apache.org/jira/browse/TOMEE-514

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/14 Ricardo <ri...@intervisit.com>

> Hi, this related to an anwer I got on a question I asked on a general Java
> forum:
>
> http://stackoverflow.com/questions/15404528/jaxb-list-with-one-element
>
> Anyone recognizes this with TomEE 1.5.1 out-of-the-box ? Seems - well, that
> is my first and quick conclusion - that TomEE is not using a JAXB
> implementation that adheres to the standard completely.
>
> What to do? I like the auto-discovery modus of TomEE, and I am not really
> ready yet for adding an extra property file, and/or adding extra jars to my
> installation.  Thanx in advance.
>
>
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/json-list-returning-one-element-lacks-square-bracket-pair-tp4661524.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>