RESTEasy does not give priority to application provided MessageBodyWriters and uses built-in providers instead.
When I create a custom MessageBodyWriter for my entity that produces text/plain MIME type my MBW is not used. Looks like built-in toString() method-based provider is used instead. I think this is a bug since it conflicts JAX-RS specification that says that application-provided providers must be used in preference to built-in providers when either can handle the request.
Issue can be reproduced on following trivial example:
public class User {
private String username;
private String email;
public User() {
}
public User(String username, String email)
{ this.username = username; this.email = email; }public String getUsername()
{ return username; }public void setUsername(String username)
{ this.username = username; }public String getEmail()
{ return email; }public void setEmail(String email)
{ this.email = email; }}
@Path("/user")
@Produces("text/plain")
public class UserResource {
private static final User user = new User("jharting", "email@example.com");
@GET
public User getUser()
}
@Provider
@Produces("text/plain")
public class UserBodyWriter implements MessageBodyWriter<User> {
public long getSize(User arg0, Class<?> arg1, Type arg2, Annotation[] arg3,
MediaType arg4)
public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2,
MediaType arg3)
public void writeTo(User arg0, Class<?> arg1, Type arg2, Annotation[] arg3,
MediaType arg4, MultivaluedMap<String, Object> arg5,
OutputStream arg6) throws IOException, WebApplicationException
private String getStringRepresentation(User user)
{ return user.getUsername() + ";" + user.getEmail(); }}
- relates to
-
RESTEASY-483 Custom MessageBodyWriter superseded by build-in MessageBodyWriter
- Closed