users@jersey.java.net

[Jersey] Sending generic collections with bounded types

From: alexg1 <alex_at_alicanto.com>
Date: Sun, 29 Jan 2012 03:48:52 -0800 (PST)

I'm trying to send send a generic collection to a resource using this
code(ResourceElement is just an empty interface):

public abstract class BaseSender<T extends ResourceElement> {
protected Collection<T> resourceElements = new ArrayList<T>();

public Collection<Message> send() {
GenericType<Collection&lt;Message>> outputGenericType = new
GenericType<Collection&lt;Message>>() {};
                        
GenericEntity<Collection&lt;T>> genericInput = new
GenericEntity<Collection&lt;T>>(resourceElements) {};
                        
return
serviceResource.type(MediaType.APPLICATION_JSON).post(outputGenericType,
genericInput);
}
}

I have a concrete class (e.g. EmailSender extends BaseSender) for each class
that implements ResourceElement. When running the code I get an exception:
"A message body writer for Java type, class java.util.ArrayList, and MIME
media type, application/json, was not found".

I thought that using GenericEntity will solve this problem but it doesn't
work. Is there any solution for this or do I have to duplicate the sending
code for each ResourceElement type?




--
View this message in context: http://jersey.576304.n2.nabble.com/Sending-generic-collections-with-bounded-types-tp7234178p7234178.html
Sent from the Jersey mailing list archive at Nabble.com.