tags:

views:

10

answers:

1

Jersey identifies requests by looking at the accept header. I have a request which accepts only text/* - How can i force the response to be for example application/json?

@POST

@Path("/create")

@Produces(MediaType.APPLICATION_JSON)

public MyResponseObject create() {

return new MyResponseObject();

}

If a request is directed to create which only accepts text/* jersey will return a 500. Is there a way to workaround this issue? (I can't change the requests accept header).

A: 

I solved this by using a servlet filter:

http://www.zienit.nl/blog/2010/01/rest/control-jax-rs-content-negotiation-with-filters

Joe