3

Here is a extract from my XML schema:

<xsd:complexType name="MyType">
    <xsd:sequence>
        <xsd:element name="Numbers">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="Number" minOccurs="1" maxOccurs="5" type="xsd:decimal"/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    </xsd:sequence>
</xsd:complexType>

JAXB generates me the following class:

public class MyType {
    protected MyType.Numbers numbers;

    public static class Numbers {
        protected List<BigDecimal> number;
    }
}

But I'd like to ignore this intermediate class and have something like:

public class MyType {
    protected List<BigDecimal> number;
}

Is that somehow possible?

Sebi
  • 2,534
  • 2
  • 26
  • 28

1 Answers1

3

Yes, that is possible with JAXB only with the help of external plugins, as this modification is actually change of the model. Have a look at @XmlElementWrapper plugin.

Note: The same question was already asked on this forum (How generate XMLElementWrapper annotation, Dealing with JAXB Collections, JAXB List Tag creating inner class). Please, use search first.

Community
  • 1
  • 1
dma_k
  • 10,431
  • 16
  • 76
  • 128
  • Thanks. But it doesn't work for me. `numbers` is now a List as expected. But the getter looks like this: `public Numbers getNumbers{ return numbers; }` So the generated classes won't compile... – Sebi Jan 05 '12 at 08:04
  • There might be a bug in the plugin :( Sorry, I can't do much with that, as I don't own that plugin. Please, publish in your question the generated code: at least it will help somebody else who will get the same problem. – dma_k Jan 05 '12 at 16:44
  • 1
    The problem was that some of my XML elements contain unterscores in the name. E.g. `last_name`. For certain reasons I had to enable `underscoreBinding="asCharInWord"`. The result was that the variable was named `lastName` and the getter `getLast_name`. So the plugin was not able to match the variable with its getter and setter methods. – Sebi Jan 06 '12 at 08:06
  • Good that is helped you. If you can publish the erroneous code + XSD, I would appreciate. – dma_k Jan 06 '12 at 11:59