4

A CXF JAX-RS application I have uses jackson to marshal POJOs to JSON. This works for the most part, but the other day it failed with a NPE when marshalling a deeply nested object.

After some investigation I found out that Jackson was included in Glassfish 3 (through Jersey) and after removing jackson-core-asl.jar, jackson-jaxrs.jar, jackson-mapper-asl.jar and jackson-xc.jar everything worked beautifully. I guess that Jackson 1.7.1 (included in GF3) had some bug that was fixed in the version shipped with my application (1.8).

Now the question is, why did I even have to do this in the first place? I would have thought libraries that are included in my war files should take presedence over any libraries in Glassfish's /modules directory.

Is there a cleaner way to do this than removing jars from the app server? Maybe there are other applications that depend on these jars ...

On a side note, the problem still exists with our GF2 container, but I cannot find any jackson libraries in the /lib folder (there is no /modules folder like in GF3). Any clues on where Jackson might be hiding in GF2 (if at all)?

Cactus
  • 27,075
  • 9
  • 69
  • 149
oligofren
  • 20,744
  • 16
  • 93
  • 180
  • Hi, Can you please share how you configured jackson in glassfish 3? I am trying to use jackson instead of jettison, with no success. Any help is appreciated. – lili Sep 06 '11 at 08:23
  • Configured? I am not quite sure what you mean. There is no configuration. Just drop the shared libraries you need in the /lib folder. If you build your programs with maven then in the dependencies section you should have something like: org.jackson jackson-core YourVersion provided – oligofren Sep 06 '11 at 14:08
  • Glassfish 3.1 comes with jettison and jackson; jettison is picked by default. I wonder how you configure it to work with jackson – lili Sep 07 '11 at 14:26

3 Answers3

8

Tell the Webapp classloader to prefer JARs provided by your WAR.

Add in your WEB-INF/sun-web.xml (or WEB-INF/glassfish-web.xml):

...
<class-loader delegate="false"/>
...

See http://jersey.java.net/nonav/documentation/latest/glassfish.html#d4e1927

Marcel
  • 266
  • 2
  • 5
1

consider using : asadmin deploy --libraries ...

Ref: http://blogs.oracle.com/alexismp/entry/more_with_deploy_libraries

oligofren
  • 20,744
  • 16
  • 93
  • 180
Alexis MP
  • 750
  • 3
  • 8
0

Jackson is included by Jersey and Hadoop, if you might be running Jersey or interact with Hadoop system; and versions included are often old. So this could be one source for "ancient Jackson" problems.

StaxMan
  • 113,358
  • 34
  • 211
  • 239
  • I am aware of that, but why should that affect me? I do not use Jersey (I use CXF JAX-RS) or Hadoop. I am a bit unsure what part of the question you are answering :) – oligofren Jul 21 '11 at 08:42
  • Just suggesting that if you were running Jersey on glassfish; or service itself was interacting with hadoop (which requires their heavyweight client), this might be a vector for old Jackson versions. Ruling out possibilities since these are common problems I've heard about. But sounds like not applicable to your case. – StaxMan Jul 21 '11 at 17:19