I have the following resource methods:
@POST
@Path("join")
@Consumes(MediaType.APPLICATION_XML)
public void processJoinNotificationFromPeer(JoiningNotification
notification) {
notifications.add(notification);
}
@POST
@Path("leave")
@Consumes(MediaType.APPLICATION_XML)
public void processLeaveNotificationFromPeer(LeavingNotification
notification) {
notifications.add(notification);
}
private final List<PeerNotification> notifications = new
ArrayList<PeerNotification>();
Ideally, I would like to merge these two methods into one:
@POST
@Path("notify")
@Consumes(MediaType.APPLICATION_XML)
public void processNotificationFromPeer(PeerNotification notification) {
notifications.add(notification);
}
But, this does not work because PeerNotification is an interface. I have
annotated the interface as shown below:
@XmlSeeAlso({JoiningNotification.class, LeavingNotification.class})
public interface PeerNotification {
Peer getPeer();
}
This is supposed to bind the implementations at JAXB runtime, but looks
like this does not work. Is this supported in Jersey?
Also, I have a generic API which returns List of PeerNotifications, but
this also suffers from the same problem.
@GET
@Path("notifications")
@Produces(MediaType.APPLICATION_XML)
public List<PeerNotification> getNotifications() {
return notifications;
}
SEVERE: A message body writer for Java class java.util.ArrayList, and Java
type java.util.List<fluximpl.cluster.events.PeerNotification>, and MIME
media type application/xml was not found
Nov 8, 2011 10:26:21 AM com.sun.jersey.spi.container.ContainerResponse write
SEVERE: The registered message body writers compatible with the MIME media
type are:
application/xml ->
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$App
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$App
*/* ->
com.sun.jersey.core.impl.provider.entity.FormProvider
com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
com.sun.jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
I have tried few other things using XmlAdapter, but none of them work.
Sounds like, this is supported in Resteasy (
http://209.132.183.68/docs/en-US/JBoss_Enterprise_Web_Platform/5/html/RESTEasy_Reference_Guide/JAXB_INTERFACES.html
).
Am I missing anything here? I am using Jersey 1.10. Appreciate your
suggestions.
Thanks!
Arul