wink-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David W Palmieri <dpalm...@us.ibm.com>
Subject Invoking MessageBodyReader.readFrom for Collection
Date Mon, 15 Nov 2010 13:40:43 GMT
I cannot seem to figure out how to invoke MessageBodyReader.readFrom() for 
a collection of objects.

I have not implemented my own MessageBodyReader.  Rather, I am trying to 
invoke the "standard" MessageBodyReader to read a collection of objects 
from the input stream.  The objects are of a class that I have defined 
using standard getters/setters.  I have confirmed that I can use the 
"standard" MessageBodyReader to read a single instance of my class of 
object.  But when I try to use the "standard" MessageBodyReader to read a 
collection of them, it fails.

Here is a snippet of code showing my attempt:

@Context private Providers providers;
@Context private HttpHeaders headers;
@Context private HttpServletRequest request;
MessageBodyReader<Collection> messageBodyReader = 
providers.getMessageBodyReader(
        Collection.class,
        MyClass.class,
        null,
        MediaType.APPLICATION_JSON_TYPE);
try {
        Collection<MyClass> myObjects = messageBodyReader.readFrom(
                Collection.class,
                MyClass.class,
                null,
                MediaType.APPLICATION_JSON_TYPE,
                headers.getRequestHeaders(),
                request.getInputStream());
} catch (IOException e) {
}

When I execute the code, I get the following IOException:
org.codehaus.jackson.map.JsonMappingException: Can not deserialize 
instance of com.mycompany.MyClass out of START_ARRAY token
 at [Source: com.ibm.ws.webcontainer.srt.http.HttpInputStream@34643464; 
line: 1, column: 1]

>From the exception, it seems that it is trying to read it as a single 
instance of MyClass, rather than a Collection.

Can anyone provide any advice or guidance?

Regards,
Dave
Mime
View raw message