You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Bryan Kearney <bk...@redhat.com> on 2009/03/31 21:58:13 UTC

Marshalling an object of type Object

This is more of a jaxb question, but I have a class like this:

class Foo {
	Object attribute ;
}

I have a webService who returns type Foo. If I pass in an ArrayList to 
the value of attribute, I get an exception which says:

javax.xml.bind.JAXBException: class java.util.ArrayList nor any of its 
super class is known to this context.


I augment the @XMLSeeAlso attribute with ArrayList as well as all the 
objects which the list could contain. This marshalls fine, but I get the 
following:

<attribute xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:ns3="http://backend.vdc.redhat.com/" xsi:type="ns3:arrayList"/>


This is fine except that there are no objects within the ArrayList. It 
looks like an empty list (not to mention that any code gen will create a 
new ArrayList (bad))

I have to create an intermediate object called AttributeCollection which 
   looks as follows:

class AttributeCollection {
	ArrayList<Attrs>
}

Is there any way to not have to create the intermediate class? And just 
have arrayList marshall correctly?

-- bk

Re: Marshalling an object of type Object

Posted by Daniel Kulp <dk...@apache.org>.
The answer is "probably not".   Normally, the "list" things are mapped to 
something like:
<element name="item" maxOccurs="unbounded" type="Attrs"/>

However, your "object"  would go to:
<element name="attribute" type="xsd:any"/>

That definition only allows a single object in it.    You COULD change it to:

Object attribute[];

and set it via setAttribute(list.toArray(new Object[]));

That would map to:
<element name="attribute" type="xsd:any" maxOccurs="unbounded"/>


Dan





On Tue March 31 2009 3:58:13 pm Bryan Kearney wrote:
> This is more of a jaxb question, but I have a class like this:
>
> class Foo {
> 	Object attribute ;
> }
>
> I have a webService who returns type Foo. If I pass in an ArrayList to
> the value of attribute, I get an exception which says:
>
> javax.xml.bind.JAXBException: class java.util.ArrayList nor any of its
> super class is known to this context.
>
>
> I augment the @XMLSeeAlso attribute with ArrayList as well as all the
> objects which the list could contain. This marshalls fine, but I get the
> following:
>
> <attribute xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ns3="http://backend.vdc.redhat.com/" xsi:type="ns3:arrayList"/>
>
>
> This is fine except that there are no objects within the ArrayList. It
> looks like an empty list (not to mention that any code gen will create a
> new ArrayList (bad))
>
> I have to create an intermediate object called AttributeCollection which
>    looks as follows:
>
> class AttributeCollection {
> 	ArrayList<Attrs>
> }
>
> Is there any way to not have to create the intermediate class? And just
> have arrayList marshall correctly?
>
> -- bk

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog