You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by pg <da...@gmail.com> on 2014/09/24 07:25:06 UTC
POJO to be returned with Content-Type: text/plain
Hi All,
I am trying to return a POJO object with Content-Type: text/plain. I am
getting below exception when calling my service:
No message body writer has been found for response class PojoClassName.
I was able to return this pojo in JSON format by setting Accept:
application/json in request header, since I have Provider configured for
JSON in my cxf-servlet.xml(org.codehaus.jackson.jaxrs.JacksonJsonProvider).
Is there a need of similar provider to be configured for text/plain content
type? Or is there any work around for it!!
Thanks, Puneet.
--
View this message in context: http://cxf.547215.n5.nabble.com/POJO-to-be-returned-with-Content-Type-text-plain-tp5749151.html
Sent from the cxf-user mailing list archive at Nabble.com.
RE: POJO to be returned with Content-Type: text/plain
Posted by Andrei Shakirin <as...@talend.com>.
Hi,
I think CXF cannot really know how to convert your custom object to text/plain message body.
Only following types will be automatically converted accordingly JAX-RS 2.0 spec:
byte[], String, InputStream, Reader, File, DataSource, StreamingOutput, java.lang.Boolean, java.lang.Character, java.lang.Number
To read/write custom object you need to define own MessageBodyReader and MessageBodyWriter; annotate them with @Produces("text/plain ") and @Consumes("text/plain"); implement isReadable(), isWritable() and readFrom(), writeTo() methods.
These MessageBodyReader, MessageBodyWriter should be registered as providers (explicitly or via annotation).
Regards,
Andrei.
> -----Original Message-----
> From: pg [mailto:dashingdudepuneet@gmail.com]
> Sent: Mittwoch, 24. September 2014 07:25
> To: users@cxf.apache.org
> Subject: POJO to be returned with Content-Type: text/plain
>
> Hi All,
>
> I am trying to return a POJO object with Content-Type: text/plain. I am getting
> below exception when calling my service:
>
> No message body writer has been found for response class PojoClassName.
>
> I was able to return this pojo in JSON format by setting Accept:
> application/json in request header, since I have Provider configured for JSON in
> my cxf-servlet.xml(org.codehaus.jackson.jaxrs.JacksonJsonProvider).
>
> Is there a need of similar provider to be configured for text/plain content type?
> Or is there any work around for it!!
>
> Thanks, Puneet.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/POJO-to-be-
> returned-with-Content-Type-text-plain-tp5749151.html
> Sent from the cxf-user mailing list archive at Nabble.com.