0

Have anyone made Jersey work at Google AppEngine with POJO Mapping to JSON? I've been spending some hours on getting this working now, but I'm stuck at two places. Running locally at Jetty I get one step further than at AppEngine, but I'm not there yet either. Here are the two problems I am encountering:

Locally:

Jetty produces the following error:

SEVERE: A message body writer for Java class
nilsnett.chinese.backend.BusinessObject, and Java type class
nilsnett.chinese.backend.BusinessObject, and MIME media type
application/json was not found

nilsnett.chinese.backend.BusinessObject is a plain Java class I've created that looks like this:

package nilsnett.chinese.backend;
import javax.xml.bind.annotation.XmlRootElement;
public class BusinessObject {
    public String text;
    public int value;
}

What is wrong here?

At AppEngine:

Uncaught exception from servlet java.lang.IncompatibleClassChangeError

Now I had this error locally as well, and it's related to the fact that I'm both referring asm-3.3.1.jar, which Jersey depends on, and asm-4.0.jar, which AppEngine depends on. If I _only_ referencedasm-4.0.jar` locally, I would get the same error here. Referencing both does obviously not work well at AppEngine. How can I get around this?

More data:

SDK's referenced:

  • AppEngine v1.7.4
  • Java SE 1.6

Jar's relevant to Jersey referenced:

  • Jersey-bundle-1.17.jar
  • Asm-3.3.1.jar
  • Jettison-1.1jar

I'm Developing in Eclipse Juno on Windows 8.

Nilzor
  • 18,082
  • 22
  • 100
  • 167

2 Answers2

1

You're importing the XmlRootElement annotation but not using it. You should add @XmlRootElement ahead of your class.

As to the second issue - have you looked at: java.lang.IncompatibleClassChangeError: Implementing class deploying to app engine ?

Community
  • 1
  • 1
condit
  • 10,852
  • 2
  • 41
  • 60
  • First issue: Did not help with `@XmlRootElement` (and it shall not be necessary). Second issue: Solved the problem - thanks! At least I can deploy now and get around the Json serialization using Gson. – Nilzor Feb 09 '13 at 12:28
0

The first problem, locally, was due to missing .jar files. I had misread the Jersey documentation and thought I only needed the files listed under chapter 11.1 Core Server and 11.4.3 JSON:

  • jettison-1.1.jar
  • jersey-bundle-1.17.jar
  • asm-3.3.1.jar

Turns out I also need the jar's listed under JAXB:

  • jackson-core-asl.jar
  • jackson-mapper-asl.jar
  • jackson-jaxrs.jar
  • jettison.jar
  • jaxb-impl.jar
  • jaxb-api.jar
  • activation.jar
  • stax-api.jar

I got fooled by the fact that the setup without the last jar's referenced worked when running in Glassfish, but that was due to the fact that the jar's come bundled with Glassfish. Not so with Jetty.

Nilzor
  • 18,082
  • 22
  • 100
  • 167