Menu

#2 Support dynamic return types for JaxB Object Collections

open
nobody
None
5
2009-08-23
2009-08-23
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

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.