JAXB problems

Discussions

XML & Web services: JAXB problems

  1. JAXB problems (1 messages)

    I'm going a bit crazy here trying to get JAXB to do what I want. The problem I'm having is when I want to have a list with more than one type of element in the list. I'm using a choice element in my schema with maxOccurs="unbounded". The problem is when I marshall, the tags of the listed elements are missing. Their children show up, unfortunately now they are the children of the parent of the list! Unmarshalling works fine. Is this a problem with JAXB, or am I misusing the choice element?

    The relevant part of the schema is something like:

    <element name="team">
      ...
      <choice maxOccurs="unbounded">
         <element name="starter">...</element>
         <element name="reserve">...</element>
      </choice>
      ...
    </element>

    The output SHOULD look like:

    <team>
      <name>SF 49ers</name>
      <starter>
        <name>Jeff Garcia</name>
        <position>QB</position>
      </starter>
      <reserve>
        <name>JJ Stokes</name>
        <position>WR</position>
      </reserve>
    </team>


    Instead I get:

    <team>
      <name>SF 49ers</name>
      <name>Jeff Garcia</name>
      <position>QB</position>
      <name>JJ Stokes</name>
      <position>WR</position>
    </team>

    The starter and reserve tags just disappear. I find this amazing since the output came from classes specifically for those tags.

    Threaded Messages (1)

  2. JAXB problems[ Go to top ]

    Choice is used to describe exactly ONE of the specified elements. Try to use sequence.