jaxb
  1. jaxb
  2. JAXB-290

xjc makes all sub-elements JAXBElement to easily for unbounded choice

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.1
    • Fix Version/s: not determined
    • Component/s: xjc
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      290

      Description

      The code generated for the unbounded choice appears to be less useful than it
      could be in some circumstances. The following schema demonstrates an example of
      this problem:

      <xsd:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xs:element name="Root">
      <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="Boolean1" type="xs:boolean"/>
      <xs:element name="Boolean2" type="xs:boolean"/>
      <xs:element name="Parameter">
      <xs:complexType>
      <xs:attribute name="name" type="xs:string"/>
      <xs:attribute name="value" type="xs:string"/>
      </xs:complexType>
      </xs:element>
      </xs:choice>
      </xs:complexType>
      </xs:element>
      </xsd:schema>

      The code generated for this is in part:

      public class Root {

      @XmlElementRefs(

      { @XmlElementRef(name = "Boolean2", type = JAXBElement.class), @XmlElementRef(name = "Boolean1", type = JAXBElement.class), @XmlElementRef(name = "Parameter", type = JAXBElement.class) }

      )
      protected List<JAXBElement<?>> boolean1OrBoolean2OrParameter;

      Instead I would have preferred:

      public class Root {

      @XmlElementRefs(

      { @XmlElementRef(name = "Boolean2", type = JAXBElement.class), @XmlElementRef(name = "Boolean1", type = JAXBElement.class), @XmlElementRef(name = "Parameter", type = Root.Parameter.class) }

      )
      protected List<Object> boolean1OrBoolean2OrParameter;

      If there was only a single boolean then the generated code would have been:

      public class Root {

      @XmlElementRefs(

      { @XmlElementRef(name = "Boolean2", type = Boolean.class), @XmlElementRef(name = "Parameter", type = Root.Parameter.class) }

      )
      protected List<Object> boolean1OrParameter;

      I understand that when it is not possible to tell the element by its type that
      it is necessary to wrap the value in a JAXBElement. It just seems that you may
      have gone too far in wrapping all of the elements in this kind of a choice case
      if there is a problem differentiating between some of them. This is
      particularly egregious for complex types because the ObjectFactory.create method
      has to be called twice, once to produce the type class and then again to produce
      the JAXBElement version of it.

        Activity

        Hide
        cezimmerman added a comment -

        should have been an Enhacement request

        Show
        cezimmerman added a comment - should have been an Enhacement request

          People

          • Assignee:
            jaxb-issues
            Reporter:
            cezimmerman
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: