users@jersey.java.net

Re: [Jersey] Returning a collection of heterogenous JAXB beans...

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 30 Apr 2009 13:43:59 +0200

Hi Mark,

It is currently not possible to support heterogeneous arrays or
collections, as you suspect you need to define a wrapper class.

Currently the array (or list element) type needs to be a JAXB bean
(XML element or XML type) type, and that type is used to derive the
root element name.

Also when marshaled there will be no special relationship between the
marshaled elements, except for the fact they are marshaled out using
the same StAX writer.

Paul.

On Apr 29, 2009, at 9:57 PM, Rabick, Mark A (IS) wrote:

> I've tried following the discussion of returning collections as
> arrays but I have an instance where I have a JAXB element called
> Node and another element called AttributeMap.
>
> Node class 'has' an AttributeMap
>
> class Node {
> public AttributeMap map;
> }
>
> I've used XmlIDRef and XmlID to map the AttributeMap.key to an
> attribute in the Node class. Basically, the attributeMap is passed
> as a distinct element outside of the xml for a Node.
>
> I would like to return the Node and AttributeMap
>
> So a method:
>
> @GET @Path("{sk}")
>
> @Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
> public Object [] getNodeBySk(@PathParam("sk") String sk) {
>
> Node node = nodeRemote.getBySk(sk);
>
> if (node == null)
> throw new NotFoundException("Node not found
> for sk: " + sk);
>
> NodeV1 nodeV1 = new NodeV1(node);
> EntityAttributeMapV1 mapV1 =
> nodeV1.getEntityAttributeMap();
>
> Object [] array = new Object [] {nodeV1, mapV1};
>
> return array;
> }
>
> I get the dreaded
>
> 2009 2:48:17 PM com.sun.jersey.spi.container.ContainerResponse write
> A message body writer for Java type, class [Ljava.lang.Object;, and
> MIME media type, application/xml, was not found
>
> Is it possible to return a collection of heterogenous JAXB beans
> without creating a 'wrapper' class? The problem is that the way I
> have the JAXB annotations on the Node object, the attributeMap is
> not included. It is done this way intentionally because multiple
> Node entities can share the same attributeMap and I don't want to
> marshall the same attribute map multiple times inside each Node that
> shares it.
>
> -mark
> _______________________________________________
> Mark A. Rabick
> Software Engineer
> Northrop Grumman - Integrated Mission Systems (IS/DSD/IMS)
> 3200 Samson Way
> Bellevue, NE 68123
> Ph: (402) 293-7091
> Em: mark.rabick_at_ngc.com
> Remember PFC Ross A. McGinnis...
> http://www.army.mil/medalofhonor/McGinnis/index.html
> ... MA2 Michael A. Monsoor, Lt. Michael P. Murphy, Cpl. Jason
> Dunham, SFC Paul Ray Smith and the rest...
> http://www.cmohs.org/recipients/most_recent.htm
>
>