0
votes

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;
    }
1
Did you try adding the @Produces annotation at the class level. It seems the problem is occurring while writing the response.CuriousMind
Of course tried @Produces but it does not solved also. Actually the project was working in Glassfish 4.0 . The problem occurs only in Glassfish 4.1 .Teymur Hacizade
I think the reason is that by default your post method produces XML, and your 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

1 Answers

0
votes

I think you have mention @Consumes("application/json") at your MessageBodyReader implementation. I have already written some custom MessageBodyWriter with @Produces. It is working fine for me. I hope this will also work for you in the case of MessageBodyReader

Refer: http://h2labz.blogspot.in/2014/12/marshalling-java-to-json-in-jax-rs.html