jaxb-tools icon indicating copy to clipboard operation
jaxb-tools copied to clipboard

-XelementWrapper:delete should not delete a WrapperClass annotated with @XmlRootElement + Bug

Open cheseaux opened this issue 1 year ago • 3 comments

I would expect classes annotated with @XmlRootElement not to be deleted by the -XelementWrapper:delete option, even if they only contain a collection. Is it a bug or an expected behavior ?

If you run my MRE at https://github.com/cheseaux/jaxb-maven-plugin-xew-bug/ you will also get a compilation error. The method createOrderItem in ObjectFactory refers to the non-existing class 'Order' (which was previously deleted by the ElementWrapper Plugin).

cheseaux avatar Feb 15 '24 16:02 cheseaux

Other xew-related plugins have an option to define which classes to 'keep'.

For example, you would want to keep 'Order', but usually delete the wrapper-only object 'Orders'

mattrpav avatar Feb 15 '24 16:02 mattrpav

@cheseaux : thanks for the MRE

-XelementWrapper plugin is quite new so we need feedback from users if working or not. We'll try to fix it soon in next release 😄

laurentschoelens avatar Feb 15 '24 16:02 laurentschoelens

The use case for annotate + xew makes more sense for inner collections.

The order object in this schema is eligble for xew deletion since it is defined only as a wrapper in the current xsd.

I think a more relevant example schema:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

    <xsd:complexType name="order">
        <xsd:sequence>
            <xsd:element name="items" type="items" minOccurs="1" maxOccurs="1"/>
        </xsd:sequence>
        <xsd:attribute type="xsd:string" name="id" use="required"/>
    </xsd:complexType>

    <xsd:complexType name="items">
        <xsd:sequence>
           <xsd:element name="item" type="item" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="item">
        <xsd:attribute type="xsd:string" name="foo" use="required"/>
    </xsd:complexType>
</xsd:schema>
  1. Object 'order' is generated and annotated with an XMLRootElement
  2. Object 'items' is replaced with List<Item> and deleted from generation (xew) as it is a pure collection wrapper object
  3. Object 'item' is generated

mattrpav avatar Feb 15 '24 17:02 mattrpav