1

Updating an OSGi/Spring web application to Jersey 2. Currently things are compiling and installing fine with Jersey 2, but I get this error when our resources are accessed:

MessageBodyWriter not found for media type=application/json, type=class org.codehaus.jettison.json.JSONObject, genericType=class org.codehaus.jettison.json.JSONObject.

Current configuration details for org.codehaus.jettison.json as ‘media provider’ for jersey.

• Added dependency on jersey-media-json-jettison

• I’m specifying the org.codehaus package here in web.xml with glassfish specific init-param:

<init-param>
      <param-name>jersey.config.server.provider.packages</param-name>
      <param-value>
                    org.codehaus.jettison.json,
                    ...
      </param-value>
</init-param>

• Added package to our webapp bundles bnd file:

org.codehaus.jettison.json,\

Which shows it’s successfully importing it in the OSGi console:

Imported packages  

org.codehaus.jettison.json; version="1.3.3"

Console also shows the package being used by the jersey-media-json-jettison bundle:

packages org.codehaus.jettison.json  
 org.codehaus.jettison.json; version="1.3.3"<org.codehaus.jettison.jettison_1.3.3 [121]>  
    org.glassfish.jersey.media.jersey-media-json-jettison_2.22.1 [192]    

Any ideas what's missing here to configure json provider?

Does using org.codehaus.jettison packages require programmatic configuration to work as json provider?

Am I asking the right questions?

thank you, Tom

Chewpers
  • 2,430
  • 5
  • 23
  • 30
TRC
  • 13
  • 5

1 Answers1

0

Jettison has a MessageBodyWriter and MessageBodyReaderfor org.codehaus.jettison.json.JSONObjects. For some reason, it does not get auto discovered, even with jettison version > 2.9 (at least for me, this was the case). Maybe because it is not annotated with @Provider. What solved this issue for me was to manually add the respective class to my ResourceConfig:

register(JettisonObjectProvider.App.class);

After this, creating responses like

Response.ok(new JSONObject(), MediaType.APPLICATION_JSON).build();

worked just like with jersey 1.

Jan Gassen
  • 3,406
  • 2
  • 26
  • 44