users@jaxb.java.net

Re: specifying minOccurs when using _at_XmlElementRef?

From: James.Strachan <james.strachan_at_gmail.com>
Date: Wed, 25 Jul 2007 03:36:06 -0700 (PDT)

James.Strachan wrote:
>
> So I really like @XmlElementRef; it means if a base class is used
> throughout a POJO model (such as a Task in the example given in the
> JavaDoc)
>
> https://jaxb.dev.java.net/nonav/jaxb20-pfd/api/javax/xml/bind/annotation/XmlElementRef.html
>
> then you don't have to litter your code on all field/properties of type
> Task with an @XmlElements({every single @XmlElement goes here}).
>
> By default the use of @XmlElementRef in code like this...
> @XmlElementRef
> List<Task> tasks;
>
> generates a choice as follows...
> <xs:choice maxOccurs="unbounded">
> <xs:element ref="jar">
> <xs:element ref="javac">
> ...
>
> I don't see a way to specify the minOccurs property. I'd like it to be
> zero by default :). Anyone any clue how you could specify 0 or 1?
>
> If there's no way to do this via the JAXB 2 standard annotations; I wonder
> if we could add an extension annotation in the com.sun.* namespace that
> the schemagen could use?
>

Am guessing this is a bug; as schemagen cannot know that the List<Task> is
always non-empty without some additional metadata. I've raised an issue

https://jaxb.dev.java.net/issues/show_bug.cgi?id=389

and attached a patch (its actually combined with the patch on issue 388 as
its a fairly trivial fix).

-- 
View this message in context: http://www.nabble.com/specifying-minOccurs-when-using-%40XmlElementRef--tf4137223.html#a11780014
Sent from the java.net - jaxb users mailing list archive at Nabble.com.