VladislavLysov
VladislavLysov

Reputation: 651

JAXB 2.0 XSD choiceContentProperty wrong behavior

I have this xsd schema:

<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
       xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="1.0">

<xs:annotation>
    <xs:appinfo>
        <jaxb:globalBindings choiceContentProperty="true"/>
    </xs:appinfo>
</xs:annotation>

<xs:element name="request1">
    <xs:complexType>
        <xs:choice>
            <xs:sequence>
                <xs:element name="request2">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element type="xs:string" name="field1"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="request3">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element type="xs:string" name="field2"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>

            <xs:element name="request4">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element type="xs:string" name="field3"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>

        </xs:choice>
    </xs:complexType>
</xs:element>

And Cxf codegen plugin generated class with List<Object> . But I need to get request2, request3, request4 fields with getters and setters in request1 class. It is possible?

Upvotes: 2

Views: 2685

Answers (1)

schnatterer
schnatterer

Reputation: 7859

Actually, setting choiceContentPropertyto true causes the elements to be mapped into one property (the List<Object>). Setting it to false changes the behavior, i.e. the elements will be wrapped into individual properties. This is explained here in more detail.

If you can't change your XSD, you should consider using a external bindings files.

<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings version="2.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <jxb:globalBindings choiceContentProperty="false" />
</jxb:bindings>

Note: This behavior can only be set globally, so changing it might affect other elements as well.

Upvotes: 3

Related Questions