On Wed, Feb 1, 2012 at 9:31 AM, Dave Schoorl <dscho...@bkwi.nl> wrote:
> Thanks for your reply. Actually, I need mapping for classes B and C to be
> abstract, because in the xml, I don't know what the containing element will
> be: it could be either Identifier1 or Identifier2 or to turn it around, in
> the xml, Identifier1 and Identifier2 could be unmarshalled to either an
> instance of class B or C, depending on the containing xml structure.
>
> To illustrate this, the following snippets of xml should both be
> unmarshallable, the first would unmarshal to an instance of class B, the
> second to an instance of class C.
>
> <Identifier1>
> <LdapName>1</LdapName>
> </Identifier1>
>
> <Identifier1>
> <IdentPart1>a</IdentPart1>
> <IdentPart2>b</IdentPart2>
> </Identifier1>
>
To my understanding, this can't work, because JiBX needs to "know" which of
A or B it's unmarshalling at the time it sees the <Identifier1> element. By
the time it recurses and starts decoding the nested elements, it's already
chosen which outer concrete binding it is decoding with.
Your only option if the XML can't be changed is to create a single class
that contains both of A's and B's fields. You could then add methods to
that class that returned an actual instance of A or B as appropriate (by
copying/mirroring the field values). This adds an ugly extra step in your
Java code but allows this XML to work.
-Archie
--
Archie L. Cobbs
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users