users@jersey.java.net

[Jersey] Re: JAXB JSON error

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Tue, 26 Feb 2013 08:05:12 -0800

On Tue, Feb 26, 2013 at 7:22 AM, Noah White <emailnbw_at_gmail.com> wrote:
> For what its worth this was 'solved' by adding the JAXB-impl and JAXB-api
> jars referenced in the guide to the class path of the Java cmd line which
> calls the main entry point that eventually starts Jetty.
>
> Still don't know why the ones bundled with JDK 1.7 were not sufficient. I
> did notice in rt.jar that the paths are a little different from what is in
> the JAXB jars, for example in rt.jar there's com.sun.xml.internal whereas in
> the jaxb-impl-2.2.4-1 jar its com.sun.xml (no 'internal' namespace).

Just a sidenote, you can also serialize JAXB annotated beans using
POJO method, with Jackson, without including JAXB implementation. The
only configuration needed is to ensure that Jackson uses
AnnotationIntrospector that recognizes and uses JAXB annotations.

-+ Tatu +-

>
> -Noah
>
> On Feb 26, 2013, at 12:34 AM, Noah White <emailnbw_at_gmail.com> wrote:
>
> The User's Guide [1] mentions the list of JARs required for non-Maven
> projects to support JSON serialization of JAXB beans.
>
> I'm investigating a problem with a project that bundles Jersey w/Jetty and a
> recent addition to the JAXBContextResolver used in the project to add
> support for NATURAL notation is now resulting in the following error
> message:
>
> INFO: Initiating Jersey application, version 'Jersey: 1.1.5.1 03/10/2010
> 02:41 PM'
> Feb 25, 2013 10:40:50 PM com.sun.jersey.api.json.JSONConfiguration natural
> SEVERE: NATURAL JSON notation configured, but JAXB RI 2.1.10 not found. For
> the recent builds to get this working correc
> tly, you need even at least JAXB version 2.1.12. Please add it to your
> classpath!
> Feb 25, 2013 10:40:50 PM com.sun.jersey.core.spi.component.ProviderFactory
> __getComponentProvider
> SEVERE: The provider class, class com.foo.JAXBContextResolver, could not be
> instantiate
> d. Processing will continue but the class will not be utilized
> java.lang.RuntimeException: NATURAL JSON notation configured, but JAXB RI
> 2.1.10 not found. For the recent builds to get
> this working correctly, you need even at least JAXB version 2.1.12. Please
> add it to your classpath!
> at
> com.sun.jersey.api.json.JSONConfiguration.natural(JSONConfiguration.java:378)
>
> As you can see this is a relatively old version of Jersey in play here. I
> looked at the old version of the User's guide [1] that covers it to double
> check the required dependencies for this feature and it looks like the
> project already has everything. It bundles jersey-bundle-1.1.5.1.jar,
> asm-3.1.jar, jsr311-api-1.1.jar, jackson-core-asl-1.1.1.jar, and
> jettison-1.1.jar and they appear on the class path at runtime.
>
> It does not explicitly bundle jaxb-impl.jar, jaxb-api.jar, activation.jar
> and stax-api.jar as these should be picked up from the 1.7.0_03 JDK/JRE
> should they not?
>
> I added -verbose:class to my VM options and verified that at start up and up
> to the error message it is pulling all the JAXB classes from the 1.7 rt.jar.
>
> This feels very similar to [2] though this project is using Jetty it bundles
> all its libs outside of jetty.home and they are listed on the java cmd line
> that invokes a class w/a MAIN which bootstraps the jetty environment so they
> end up in the classloader that starts jetty vs the webapp class loader (not
> my doing :-).
>
> Any thoughts on what could going on here?
>
> Thanks,
>
> -Noah
>
> [1] -
> http://jersey.java.net/nonav/documentation/1.1.5/user-guide.html#chapter_deps
> [2] -
> http://stackoverflow.com/questions/10032032/jaxb-issues-under-java-7-it-says-it-cant-find-ri-2-1-0
>
>