I think strings/string is acceptable. If users want a better representation
of their data, they can create an object to wrap their strings. I've done
this in my application and no longer need String[] support, but I can see
how it might be useful for others.
Matt
Sergey Beryozkin wrote:
>
> No, there're no utilities (in CXF) for wrapping String values into
> corresponding name:value JSON sequences or xml elements.
> What sort of wrapper names would be acceptable for Strings ?
> is it 'string' ?
>
> so List<String> can be then be serialized like :
> <strings>
> <string>foo</string>
> <string>foo</string>
> <strings>
>
> or
>
> {{"string":"foo"},{"string":"bar"}}
>
> ?
>
> cheers, Sergey
>
>
> mraible wrote:
>>
>> That fixed it - thanks!
>>
>> Now I just need to figure the best way to write the output to JSON and
>> XML. Are there some utilities I can use or should I just construct a
>> StringBuffer with the necessary wrapper characters?
>>
>> Thanks,
>>
>> Matt
>>
>>
>> Sergey Beryozkin wrote:
>>>
>>> Hi
>>>
>>> What about isWriteable() code ? This code does not seem right :
>>>
>>> type.equals(ArrayList.class)
>>>
>>> can you please change it to something like :
>>> List.class.isAssignableFrom(type) ?
>>>
>>> Can you add a breakpoint to isWriteable ?
>>>
>>> cheers, Sergey
>>>
>>>
>>>
>>> mraible wrote:
>>>>
>>>> I thought I replied to this a couple weeks ago, but apparently not. I'm
>>>> still experiencing this error even after adding
>>>> @Produces({"text/xml","text/plain","application/json"}).
>>>>
>>>> Thanks,
>>>>
>>>> Matt
>>>>
>>>>
>>>> Sergey Beryozkin wrote:
>>>>>
>>>>> 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---tp25070046p25258484.html
Sent from the cxf-user mailing list archive at Nabble.com.