users@jersey.java.net

[Jersey] Fwd: Re: Fwd: Re: Upgrading from 1.2 to Jersey 1.4 breaks JSON?

From: Dominique Guinard <dev_at_guinard.org>
Date: Tue, 11 Jan 2011 10:11:20 -0500

Dear all,

Any news about that?
Did anyone experience this problem as well?


Hi Jakub,
> i have responded to the mailing list, not sure your address was included
> there.
> Please see the original message bellow.
>
Sorry about that, I never got the answer although I'm supposed to be on
the mailing list. Anyways... thanks!

> On the breaking change: could you please provide some details
> on your configuration? It seems that it depends on environment
> settings if the change in JSON formatting happens or not.
> I would like to know more details so that i can help fix this.
Ok, see below


>> Is this an actual bug? To me it seems like Jackson fires directly when
>> trying to create JSON objects, taking the precedence on JAXB.
>> I attached two json files to this mail, one with jersey 1.2 one with
>> 1.4 without changing anything else, just the POM.
>
> It seems that in certain environments, the default behavior changed, but
> it was not the intent.
> What container/configuration do you use?
>
I use Apache Tomcat 6.x (actually this happened on our production
server, an Apache Tomcat/6.0.24 and our test server an Apache Tomcat/6.0.26.

For the sake of it I just tested on Glassfish v3 and get the same
behavior: Jackson is activated by default.

What do else do you mean configuration? I actually do not use any
particular parameter. Here is my Web.xml:

<web-app version="2.5" 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/web-app_2_5.xsd">
      <servlet>
          <servlet-name>ServletAdaptor</servlet-name>

<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
          <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
          <servlet-name>ServletAdaptor</servlet-name>
          <url-pattern>/rest/*</url-pattern>
      </servlet-mapping>
      <session-config>
          <session-timeout>
              30
          </session-timeout>
      </session-config>
      <welcome-file-list>
          <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
</web-app>

and my POM is attached.


> You only need to define a new provider for the object mapper context
> resolver.
> Following is a simple implementation:
>
> @Provider
> public class MyObjectMapperProvider implements
> ContextResolver<ObjectMapper>{
>
> @Override
> public ObjectMapper getContext(Class<?> type) {
> final ObjectMapper myMapper = new ObjectMapper();
> myMapper.configure(Feature.WRITE_NULL_PROPERTIES, false);
> return myMapper;
> }
> }
>
> HTH,
>
That would be one way, the problem is that not only there are null
values but also the result itself has some breaking differences (e.g.,
in the way lists are treated see attached files), as a results it breaks
the JSON "API" or syntax that clients of our framework are using.

So, for us, it would actually be really nice to be able to make sure
that JAXB and not Jackson fires by default.

Having said that I also wanted to add support for jsonp for which I'll
need Jackson if I got it correctly (but that's a least priority than not
breaking JSON syntax.


Thanks,

Dominique
> ~Jakub
>
>
>>
>> Any help is warmly welcomed,
>
>
>