0

I couldn't find any information about that... it's a strange behavior :

When passing data using SOAP here - everything works fine

@Data
@XmlRootElement
//@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="Test")
public class Test {

     private TestInternal testInternalHello; //class: TestInternal and name testInternalHello have different names

}

Here is the xsd :

<xs:complexType name="myTest">
    <xs:sequence>
        <xs:element name="Test" type="tns:Test" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>
<xs:complexType name="Test">
    <xs:sequence>
        <xs:element name="testInternalHello" type="tns:TestInternal" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>
<xs:complexType name="TestInternal">
    <xs:sequence>
        <xs:element name="str1" type="xs:string" minOccurs="0"/>
        <xs:element name="str2" type="xs:string" minOccurs="0"/>
        <xs:element name="testAnother" type="tns:TestAnother" nillable="true"/>
    </xs:sequence>
</xs:complexType>
<xs:complexType name="TestAnother">
    <xs:sequence>
        <xs:element name="lastTest" type="xs:boolean"/>
        <xs:element name="something" type="xs:string" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>

If I use same name - and pass exactly the same data - the object passes as null:

    @Data
@XmlRootElement
//@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="Test")
public class Test {

     private TestInternal testInternal; //class: TestInternal and name testInternal have the same name

}

this is the second:

<xs:complexType name="myTest">
    <xs:sequence>
        <xs:element name="Test" type="tns:Test" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>
<xs:complexType name="Test">
    <xs:sequence>
        <xs:element ref="tns:testInternal" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>
<xs:complexType name="TestInternal">
    <xs:sequence>
        <xs:element name="str1" type="xs:string" minOccurs="0"/>
        <xs:element name="str2" type="xs:string" minOccurs="0"/>
        <xs:element ref="tns:testAnother" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>
<xs:complexType name="TestAnother">
    <xs:sequence>
        <xs:element name="lastTest" type="xs:boolean"/>
        <xs:element name="something" type="xs:string" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>

THE ONLY thing that work is if I add an @XmlElement annotation with NILLABLE=true ... I just can't understand why or how to solve it. I don't want all my object to be nillable... and I don't see a reason starting to go over the code and change all the equal names..

@Data
@XmlRootElement
//@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="Test")
public class Test{

    @XmlElement(required = true, nillable = true)
    private TestInternal testInternal; //THIS WORKS

}

Adding the classes and the xml & xsd

user1386966
  • 3,302
  • 13
  • 43
  • 72

0 Answers0