users@jersey.java.net

[Jersey] Application/json for JAXB class failed in 1.10

From: Brendan cheng <ccp999_at_hotmail.com>
Date: Wed, 26 Oct 2011 10:50:13 +0000

Hi,
I'm learning JAXB XmlRootElement for a simple POJO object.
I did successfully run 
System.out.println(service.path("examples").path("unmanaged")
.path("todo").accept(MediaType.APPLICATION_XML)
.get(String.class));
but not
System.out.println(service.path("examples").path("unmanaged") .path("todo").accept(MediaType.APPLICATION_JSON) .get(Todo.class));
and the error is.
Exception in thread "main" com.sun.jersey.api.client.UniformInterfaceException: GEThttp://192.168.56.101:7474/examples/unmanaged/todo returned a response status of 500 Internal Server Error
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:676)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:503)
at hk.itags.server.unmanaged.Test.main(Test.java:40)
I copied the examples from a web site which I put here:
package hk.itags.server.unmanaged;


import javax.xml.bind.annotation.XmlRootElement;


@XmlRootElement
// JAX-RS supports an automatic mapping from JAXB annotated class to XML and JSON
// Isn't that cool?
public class Todo {
private String summary;
private String description;
private int number;
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public void setSummary(int number) {
this.number = number;
}
public int getNumber() {
return number;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
and the resource
package hk.itags.server.unmanaged;


import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;


@Path("/todo")
public class TodoResource {
// This method is called if XMLis request
@GET
@Produces( { MediaType.APPLICATION_XML })
public Todo getXML() {
Todo todo = new Todo();
todo.setSummary("This is my 1 todo");
todo.setDescription("This is my 1 todo");
todo.setSummary(345);
return todo;
}

@GET
@Produces( { MediaType.APPLICATION_JSON})
public Todo getJSON() {
Todo todo = new Todo();
todo.setSummary("This is my third todo");
todo.setDescription("This is my third todo");
todo.setSummary(347);
return todo;
}

// This can be used to test the integration with the browser
@GET
@Produces( { MediaType.TEXT_XML })
public Todo getHTML() {
Todo todo = new Todo();
todo.setSummary("This is my 2 todo");
todo.setDescription("This is my 2 todo");
todo.setSummary(346);
return todo;
}


}