tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From José Luis Cetina <maxtorz...@gmail.com>
Subject Re: serializeAsArray JacksonJaxbJsonProvider
Date Mon, 20 Oct 2014 15:49:01 GMT
I could find what was my problem

I was setting the jackson scope dependecy to provided.

 <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
            <version>2.2.3</version>
            <scope>provided</scope>
        </dependency>

I dont know if jettison is the default provider in CXF, thats why when
TomEE runs it was using the default CXF provider NOT jackson.

Then i chance provided to compile

 <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
            <version>2.2.3</version>
            <scope>compile</scope>
</dependency>


Thanks

2014-10-20 10:27 GMT-05:00 Romain Manni-Bucau <rmannibucau@gmail.com>:

> 2014-10-20 17:21 GMT+02:00 José Luis Cetina <maxtorzito@gmail.com>:
> > 1. If i use jackson do i have the same "serializeAsArray" trouble?  (I
> thought
> > i was using jackson, see my first mail in this conversation)
> >
>
> Johnzon and Jackson are "what you expect" mot of the time.
>
> > 2. How do i define my Jacksonprovider, i try to do what is suggested
> here:
> >
> http://stackoverflow.com/questions/5951323/how-to-configure-json-format-when-using-jaxb-annotations-with-jersey
> >
>
> You can do it as well, the jar will be scanned and it will be added as
> provider...but will surely conflict with default providers (I never
> said scaninng was good ;)). best solution is surely to add it in
> openejb-jar.xml as you did:
>
> <openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance"
>              xsi:schemaLocation="http://www.openejb.org/openejb-jar/1.1 ">
>     <pojo-deployment class-name="jaxrs-application">
>          <properties>
>             cxf.jaxrs.providers =
> com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider
>         </properties>
>     </pojo-deployment>
> </openejb-jar>
>
> note you can also give it to classes of your jaxrs Application child.
>
> >
> > But i get an SEVERE: can't instantiate xxx.providers.MyJsonProvider
> > java.lang.InstantiationException: xxx.providers.MyJsonProvider
> >
> >
>
> No default constructo rmaybe?
>
> >
> > 3. I cant find any doc  for configure Jackson on TomEE, is there any
> guide
> > in tomee's website?
> >
> >
>
> Nothing specific to jackson since we don't do more than any jaxrs provider.
>
> >
> > 4. I was using jackson provider correctly?
> >
> > With this config:
> >
> > <openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1" xmlns:xsi="
> > http://www.w3.org/2001/XMLSchema-instance"
> >              xsi:schemaLocation="http://www.openejb.org/openejb-jar/1.1
> ">
> >     <pojo-deployment class-name="jaxrs-application">
> >          <properties>
> >             cxf.jaxrs.providers =
> > com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
> >         </properties>
> >     </pojo-deployment>
> > </openejb-jar>
> >
> >
>
> I fyou don't have any jaxrs Application yes (ensure you are on a
> single line without spaces)
>
> >
> > Im using TomEE 1.7.1 JAX-RS
> >
> >
> >
> > 2014-10-20 9:50 GMT-05:00 Romain Manni-Bucau <rmannibucau@gmail.com>:
> >
> >> 2014-10-20 16:49 GMT+02:00 Alex Soto <asotobu@gmail.com>:
> >> > BTW is johnzon already integrated in trunk of TomEE?
> >> >
> >>
> >> yep
> >>
> >> > 2014-10-20 16:48 GMT+02:00 Romain Manni-Bucau <rmannibucau@gmail.com
> >:
> >> >
> >> >> well I stopped trying to get what I want with jettison since years.
> >> >> The usage of jaxb tree to get json is quite broken in several places
> >> >> so my advice would be to use either johnzon jaxrs provider or
> jackson.
> >> >>
> >> >>
> >> >> Romain Manni-Bucau
> >> >> @rmannibucau
> >> >> http://www.tomitribe.com
> >> >> http://rmannibucau.wordpress.com
> >> >> https://github.com/rmannibucau
> >> >>
> >> >>
> >> >> 2014-10-20 16:44 GMT+02:00 José Luis Cetina <maxtorzito@gmail.com>:
> >> >> > Thanks, now its working.
> >> >> >
> >> >> > But now all of my object's are serialize as array, do i have to
map
> >> each
> >> >> > pojo and set the attributes that i need to serializeAsArray ?
> >> >> >
> >> >> >
> >> >> > public class MyObject{
> >> >> >    int id;  String name;
> >> >> > }
> >> >> >
> >> >> > public MyObject getInfo(){
> >> >> >    return new MyObject();
> >> >> > }
> >> >> >
> >> >> > Now my json return value es:
> >> >> >  myObject: [{id:1, name:'any'}]
> >> >> >
> >> >> > and i expected to be:
> >> >> >  myObject: {id:1, name:'any'}
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > 2014-10-20 8:38 GMT-05:00 Romain Manni-Bucau <
> rmannibucau@gmail.com>:
> >> >> >
> >> >> >> <openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1"
> >> xmlns:xsi="
> >> >> >> http://www.w3.org/2001/XMLSchema-instance"
> >> >> >>              xsi:schemaLocation="
> >> http://www.openejb.org/openejb-jar/1.1
> >> >> ">
> >> >> >>     <pojo-deployment  class-name="jaxrs-application">
> >> >> >>          <properties>
> >> >> >>             cxf.jaxrs.providers = json
> >> >> >>         </properties>
> >> >> >>     </pojo-deployment>
> >> >> >> </openejb-jar>
> >> >> >>
> >> >> >>
> >> >> >> resources.xml
> >> >> >>
> >> >> >> <resources>
> >> >> >>     <Service id="json"
> >> >> >> class-name="org.apache.cxf.jaxrs.provider.json.JSONProvider">
> >> >> >>         serializeAsArray = true
> >> >> >>     </Service>
> >> >> >> </resources>
> >> >> >>
> >> >> >>
> >> >> >> jackson doesn't have any setter so you have to do your own
> wrapper to
> >> >> >> provide the properties you want to configure (or hardcode
them)
> >> >> >>
> >> >> >>
> >> >> >>
> >> >> >>
> >> >> >> Romain Manni-Bucau
> >> >> >> @rmannibucau
> >> >> >> http://www.tomitribe.com
> >> >> >> http://rmannibucau.wordpress.com
> >> >> >> https://github.com/rmannibucau
> >> >> >>
> >> >> >>
> >> >> >> 2014-10-20 15:34 GMT+02:00 José Luis Cetina <maxtorzito@gmail.com
> >:
> >> >> >> > I changed to:
> >> >> >> >
> >> >> >> > <openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1"
> >> >> xmlns:xsi="
> >> >> >> > http://www.w3.org/2001/XMLSchema-instance"
> >> >> >> >              xsi:schemaLocation="
> >> >> http://www.openejb.org/openejb-jar/1.1
> >> >> >> ">
> >> >> >> >     <pojo-deployment  class-name="jaxrs-application">
> >> >> >> >          <properties>
> >> >> >> >             cxf.jaxrs.providers =
> >> >> >> > com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
> >> >> >> >         </properties>
> >> >> >> >     </pojo-deployment>
> >> >> >> > </openejb-jar>
> >> >> >> >
> >> >> >> >
> >> >> >> > resources.xml
> >> >> >> >
> >> >> >> > <resources>
> >> >> >> >     <Service id="json"
> >> >> >> >
> >> class-name="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider">
> >> >> >> >         serializeAsArray = true
> >> >> >> >     </Service>
> >> >> >> > </resources>
> >> >> >> >
> >> >> >> >
> >> >> >> > and didnt work, what is the value of id in service tag?
is json
> >> >> correct?
> >> >> >> do
> >> >> >> > i have to set the same class name in both files?? i really
dont
> >> >> >> understand
> >> >> >> > this config.
> >> >> >> >
> >> >> >> > 2014-10-19 2:24 GMT-05:00 Romain Manni-Bucau <
> >> rmannibucau@gmail.com>:
> >> >> >> >
> >> >> >> >> If you have a custom jaxrs application class-name
should be its
> >> name.
> >> >> >> >>
> >> >> >> >> And once you use resources, providers values should
be their
> ids
> >> >> (json
> >> >> >> >> here) in openejb-jar.
> >> >> >> >>  Hi,
> >> >> >> >> I usually add my own @provider / "extends
> >> JacksonJaxbJsonProvider")
> >> >> >> >>
> >> >> >> >> and set all my needed objectmapper options there.
> >> >> >> >>
> >> >> >> >> br hw
> >> >> >> >>
> >> >> >> >>
> >> >> >> >>
> >> >> >> >> --
> >> >> >> >> View this message in context:
> >> >> >> >>
> >> >> >> >>
> >> >> >>
> >> >>
> >>
> http://tomee-openejb.979440.n4.nabble.com/serializeAsArray-JacksonJaxbJsonProvider-tp4672427p4672431.html
> >> >> >> >> Sent from the TomEE Users mailing list archive at
Nabble.com.
> >> >> >> >>
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > --
> >> >> >> >
> -------------------------------------------------------------------
> >> >> >> > *José Luis Cetina*
> >> >> >> >
> -------------------------------------------------------------------
> >> >> >>
> >> >> >
> >> >> >
> >> >> >
> >> >> > --
> >> >> > -------------------------------------------------------------------
> >> >> > *José Luis Cetina*
> >> >> > -------------------------------------------------------------------
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > +----------------------------------------------------------+
> >> >   Alex Soto Bueno - Computer Engineer
> >> >   www.lordofthejars.com
> >> > +----------------------------------------------------------+
> >>
> >
> >
> >
> > --
> > -------------------------------------------------------------------
> > *José Luis Cetina*
> > -------------------------------------------------------------------
>



-- 
-------------------------------------------------------------------
*José Luis Cetina*
-------------------------------------------------------------------

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message