I am working on Restful service. The problem occurred after we moved to Glassfish 4.1 . The error string is :
SEVERE: MessageBodyWriter not found for media type=application/xml, type=...
But my classes consume application/json. Here is example:
@Path("get_customer_info")
@Consumes("application/json;charset=utf8")
public class CustomerInfoResource {
@Context
private UriInfo context;
public CustomerInfoResource () {
}
@POST
public Player getPlayerInfo(){
....
}
}
I have done the following and could not solve it: Added all jersey jars version 2.13 , jackson jars 2.4.3 . Also added jersey-media-json-jackson-2.13.jar which contains org.glassfish.jersey.jackson.JacksonFeature class. By the way ApplicationConfig class is:
@javax.ws.rs.ApplicationPath("resources")
public class ApplicationConfig extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<Class<?>>();
try {
Class jsonProvider = Class.forName("org.glassfish.jersey.jackson.JacksonFeature");
resources.add(jsonProvider);
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
addRestResourceClasses(resources);
return resources;
}
Player
class is not serializable. If you want to get around this easily, and you don't mind returning Json, you could use something like Gson and then do something like this:BagOfPrimitives obj = new BagOfPrimitives(); Gson gson = new Gson(); String json = gson.toJson(obj);
– frmi