我有一个webservice soap服务,它将带有可选列表的对象作为xml参数:
<xs:complexType name="objectType">
<xs:sequence>
<xs:element name="Sleutel1" type="StringMax128Type" nillable="true" minOccurs="0" maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="StringMax128Type">
<xs:annotation>
<xs:documentation>String with max 128 characters</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:maxLength value="128"/>
</xs:restriction>
</xs:simpleType>
我希望这些场景的结果如下:
SCENARIO 1:请求中不包含任何标记。 结果:sleutel1 = null
<soapenv:Body>
<upd:Update version="1.0">
<Info>
</Info>
</upd:Update>
</soapenv:Body>
SCENARIO 2:请求包含空标记。 结果:sleutel1 =空列表
<soapenv:Body>
<upd:Update version="1.0">
<Info>
<Sleutel1></Sleutel1>
</Info>
</upd:Update>
</soapenv:Body>
SCENARIO 3:请求包含填充标记。 结果:sleutel1 =填充列表
<soapenv:Body>
<upd:Update version="1.0">
<Info>
<Sleutel1>A</Sleutel1>
<Sleutel1>B</Sleutel1>
<Sleutel1>C</Sleutel1>
</Info>
</upd:Update>
</soapenv:Body>
但由于某种原因,它总是想要返回一个空的arraylist而不是null?是否可以删除此规则以始终返回新的arraylist?我的服务更新了一个对象,我希望有一个空值,以便我可以看到不想更新此特定值的请求或想要删除或添加到该值的请求之间的区别。
以下代码来自架构。
@XmlElement(name = "Sleutel1", nillable = true)
protected List<String> sleutel1;
/**
* Gets the value of the sleutel1 property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the sleutel1 property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getSleutel1().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link String }
*
*
*/
public List<String> getSleutel1() {
if (sleutel1 == null) {
sleutel1 = new ArrayList<String>();
}
return this.sleutel1;
}