Hi Søren, This is an unfortunate loophole in the current code, where nillable='true' is not directly usable when the value is defined as a base type extended by other types. In order to handle this correctly from the schema point of view (which is where the whole nillable thing comes from in the first place) JiBX would need to pick one of the classes with concrete mappings to use for a null (so in your case, the null value would have to be either a Bar or a Boo). I find that really ugly - but that's schema.
For now, the best I can suggest is to use a custom marshaller which looks at each value in the array. If the value is non-null it just marshals it directly; if the value is null, the custom marshaller would need to get the marshaller instance for either Bar or Boo and pass the null value to that marshaller. The JiBX-generated marshaller code should then generate the element with xsi:nil='true'. - Dennis Dennis M. Sosnoski SOA and Web Services in Java Training and Consulting http://www.sosnoski.com - http://www.sosnoski.co.nz Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117 Søren Andersen wrote: > Hi, > > I've stumbled into the following problem that I'm not 100% sure how to > handle. > > I have the following situation: > > abstract class Foo { > > } > > class Bar extends Foo { > > } > > class Boo extends Foo { > > } > > class Baz { > private Foo[] fooElements; > } > > where fooElements can contain nulls. However, trying to marshal this > only brings nullpointerexceptions. > I read: > http://sourceforge.net/mailarchive/[EMAIL PROTECTED] > however, the nillable="true" method does not seem to work for me here > (I've added it to the Bar and Boo mappings. Foo cannot take it, as it > is abstract), nor can I compact the array as I need the objects to be > 100% the same after a marshal / unmarshal. > I guess it isn't that strange that it isn't handled. Foo is abstract, > so how exactly would it represent a null? > > My only real idea for how to solve this is to write a custom > marshaller / unmarshaller to handle this (and create a custom <null /> > element for it), but I'd rather not if it can be avoided. > I'd also like to avoid adding another object between the abstract Foo > and the concrete classes, if possible... > > I may just be asking too much of the framework here and the custom > marshaller / unmarshaller is the best option, but experience tells me > there are loads of people smarter than me, and perhaps someone out > there has already solved this :-) > > Regards, > > Søren Andersen > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > ------------------------------------------------------------------------ > > _______________________________________________ > jibx-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/jibx-users > ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ jibx-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jibx-users
