Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB generated classes: Ignore intermediate classes

Tags:

jaxb

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?

like image 607
Sebi Avatar asked May 09 '26 06:05

Sebi


1 Answers

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.

like image 100
dma_k Avatar answered May 11 '26 23:05

dma_k



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!