Hi
CXF 2.2.3 only supports the arrays/collections of JAXB beans. I've added a
task to support the explicit collections/arrays of arbitrary (non-JAXB)
types.
Now, as far as your provider is concerned, I think the problem is to do with
this declaration :
@Produces("text/xml,text/plain,application/json")
try this instead :
@Produces({"text/xml","text/plain","application/json"})
let me know if it works please...
cheers, Sergey
mraible wrote:
>
> I'm getting this message when trying to return a String[] from a RESTful
> service. After searching the mailing list, it seems the best solution is
> to change my method to return a List<String> and create a
> StringListBodyWriter as a provider. However, after doing that, I'm still
> getting a similar error:
>
> No message body writer found for response class : ArrayList
>
> Here's my StringArrayBodyWriter:
>
> @Provider
> @Produces("text/xml,text/plain,application/json")
> public class StringListBodyWriter implements
> MessageBodyWriter<List<String>> {
>
> public long getSize(List<String> t, Class<?> type, Type genericType,
> Annotation[] annotations, MediaType mediaType) {
> Iterator<String> i = t.iterator();
> long size = 0;
> while (i.hasNext()) {
> size += i.next().length();
> }
> return size;
> }
>
> public boolean isWriteable(Class<?> type, Type genericType,
> Annotation[] annotations, MediaType
> mediaType)
> {
> return type.equals(ArrayList.class)
> && (mediaType.equals(MediaType.TEXT_PLAIN_TYPE)
> |
> mediaType.equals(MediaType.TEXT_XML_TYPE) |
>
> mediaType.equals(MediaType.APPLICATION_JSON_TYPE));
> }
>
> public void writeTo(List<String> t, Class<?> type, Type genericType,
> Annotation[] annotations, MediaType mediaType,
> MultivaluedMap<String, Object> httpHeaders,
> OutputStream entityStream) throws IOException,
> WebApplicationException {
> BufferedWriter bw = new BufferedWriter(new
> OutputStreamWriter(entityStream));
> String ts = null;
> for (String aT : t) {
> ts += aT;
> }
> bw.write(ts);
> bw.flush();
> }
> }
>
> Registered in Spring:
>
> <bean id="stringListProvider"
> class="com.company.app.service.StringListBodyWriter"/>
>
> .....
>
> <jaxrs:server id="restServer" address="/rest/">
> <jaxrs:serviceBeans>
> ...
> </jaxrs:serviceBeans>
> <jaxrs:providers>
> <ref bean="jsonProvider"/>
> <ref bean="stringListProvider"/>
> </jaxrs:providers>
>
> Am I doing something wrong? I'm using CXF 2.2.3.
>
> Thanks,
>
> Matt
>
--
View this message in context:
http://www.nabble.com/No-message-body-writer-found-for-response-class-%3A-String---tp25070046p25076144.html
Sent from the cxf-user mailing list archive at Nabble.com.