[jax-rs-spec users] [jsr339-experts] Error responses with entities and the media types

From: Sergey Beryozkin <>
Date: Wed, 13 Mar 2013 14:20:46 +0000


We've talked about it before, in context of the exception mappers
mapping the exceptions to Responses with non empty entities,

example, the client Accepts application/xml, the server throws an
exception, the mapper maps it to

Response.status(400).type("text/plain").entity("Bad response").build().

and this is exactly what the client should get back despite expecting
only XML.

However, consider that either the application code or even the exception
mapper does


This is clearly an error that is better be detected by the server
runtime, before the client code like "client.get(StreamSource.class)"
reports something like "{" is not allowed in XML, etc.

Should the spec say that if Response status is >=400 and the entity is
not null then this Response media type whatever it is, is used;
otherwise, if Response is 200, the entity is not null, then the runtime
should treat its media type the same way it treats @Produces ?