cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Beryozkin (JIRA)" <>
Subject [jira] [Commented] (CXF-6796) Improve or extend StringTextProvider to write an Object
Date Tue, 23 Feb 2016 10:52:18 GMT


Sergey Beryozkin commented on CXF-6796:

Hi Jim, 

If we relax StringTextProvider to accept Object then it will start competing with PrimtiveTextProvider
which handles Boolean/Number/etc such that a spec requirement (that Boolean/Number/etc are
only supported OOB if it is text/plain) will be broken if it is say 'text/html', etc.

For example, suppose we have a client with Accept: texthtml and the method returns Boolean,
and  if StringTextProvider accepts object then it will be chosen and return Boolean.

In fact it will convert Order to String even it is Accept: application/json if for some reasons
the default Jettison or Jackson won't be able to write it and that would be a problem.

The easiest thing to do is simply to create a custom text/plain MessageBodyWriter that will
convert arbitrary objects to String. The other option is to write ContainerResponseFilter
which will convert the response body to String and then will reset it on the response container
context - so that the client code does not convert to String

Cheers, Sergey  

> Improve or extend StringTextProvider to write an Object 
> --------------------------------------------------------
>                 Key: CXF-6796
>                 URL:
>             Project: CXF
>          Issue Type: Improvement
>          Components: JAX-RS
>    Affects Versions: 3.1.5
>            Reporter: Jim Ma
>             Fix For: 3.1.6
> CXF reports it can't find the message writer for  OrderModel class and text/plain content
type when the resource class like the following:  
> {code}
> @Produces("text/plain")
> @Path("order/{id}")
> public class OrderResource {
>    @GET
>     public OrderModel get(@PathParam("id") @CustomMax int id) {
>         return new OrderModel(id);
>     }
> }
> {code}
> It is required to change the return Class to String and explicitly invoke toString()
return the String value
> {code}. 
> @Produces("text/plain")
> @Path("order/{id}")
> public class OrderResource {
>     @GET
>     public String get(@PathParam("id") @CustomMax int id) {
>         return new OrderModel(id).toString();
>     }
> }
> {code}
> We can improve StringTextProvider to write the Object with toString value to remove the
return type must be String class restriction.

This message was sent by Atlassian JIRA

View raw message