users@jaxb.java.net

Re: [java.lang.InstantiationException] at unmarshal step

From: Dmitry <redmitry_at_list.ru>
Date: Thu, 29 Oct 2009 11:12:55 +0100

Hello Raphaël,

Thinking a little bit more about...
I think you can not keep your tag "biosource" and map it to different
JAXB objects (even with xsi:type attribute in your XML).

You can map your abstract Biosource class to the
<xs:complexType name="biosource" abstract="true"> (without defining
@XmlTransient)

and explicitly specify children on list:
@XmlElementRefs({_at_XmlElementRef(name = "client_biosource", type =
ClientBiosource.class)})

I don't know how to do it better...

Cheers,

D.


Raphaël Flores wrote:
> Hi Dmitry,
>
> I know abstract class can cause some problem, it is for this reason I
> give its subclass to JAXBContext as Kohsuke Kawaguchi suggested on
> this article:
> http://weblogs.java.net/blog/kohsuke/archive/2006/04/why_doesnt_jaxb.html
>
> Adding subclass in parameter made unmarshall of Biosource OK. So why
> not with List<Biosource>? But I have to check if Biosource is
> unmarshalled only based on ClientBiosource or if the Biosource class
> is necessary. In first case, it would change my approach because
> currently, I need Biosource class to be abstract because the method
> getBiosource() implementation may vary upon the location from where
> the subclass is created (client or server side).
>
> If you have another suggestion, let me know. In all case, I'll look
> for these checkings tomorrow morning when I'll come back office and I
> will let you informed.
>
> Thanks,
>
> Raphaël.
>