Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#2 Support dynamic return types for JaxB Object Collections

open
nobody
None
5
2009-08-23
2009-08-23
William Bath
No

Marshalling/UnMarshalling of Collections of JaxB objects only appears to work for methods that explicity return an object of type Collection... e.g.

public HashSet<Tag> getTags();

Where Tag is a JaxB annotated object. This will work and JaxB will marshall/unmarshall appropriately. However replace the return type with java.lang.Object:

public java.lang.Object getTags();

and attempting to call the method results in "Could not find MessageBodyWriter for response object of type: java.util.HashSet of media type: text/xml".

Adding this capability would mean provide better support for one method returning different representations depending upon content negotiation e.g.

@GET
@Produces( {
MediaType.TEXT_XML,
MediaType.APPLICATION_XML,
MediaType.APPLICATION_JSON,
MediaType.APPLICATION_XHTML_XML,
MediaType.APPLICATION_ATOM_XML
})
@Path("/tags")
public abstract Object getTagsCanonical(@HeaderParam("Accept") String mediaType);

This method could look at the mediatype and return a Feed, a ModelAndView or a collection of tags accordingly.

Discussion