肥皂对我来说是一项新技术。我收到一个 Soap 消息请求,这是其中的一部分
<patient>
<dateOfBirth>
<year></year>
<month></month>
<day></day>
</dateOfBirth>
<firstName>Ivan</firstName>
<lastName>Luku</lastName>
</patient>
这是这部分的 xsd 模式。
xs:complexType name="personVO">
<xs:complexContent>
<xs:extension base="tns:tenantableVO">
<xs:sequence>
<xs:element name="dateOfBirth" type="tns:localDateVO"/>
<xs:element name="firstName" type="xs:string"/>
<xs:element name="lastName" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
------------------------------------------
<xs:complexType name="localDateVO">
<xs:sequence>
<xs:element name="day" type="xs:int" nillable="true" minOccurs="0"/>
<xs:element name="month" type="xs:int" nillable="true" minOccurs="0"/>
<xs:element name="year" type="xs:int" nillable="true" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
如您所见,dateOfBirth 标签中的年、日、月为空值。这个变量在 java 代码中呈现为 Integer 类型。收到这个请求后,我应该怎么做才能让这个变量为空?
我尝试在get方法上面写注解,但是没有用。当我写注释 @XmlAttribute 时,无论是否有值,它总是给我 null。
@XmlAttribute
public Integer getDay() {
return day;
}
@XmlAttribute
public Integer getMonth() {
return month;
}
@XmlAttribute
public Integer getYear() {
return year;
}
我尝试为字段做相同的注释,但它给我这样的错误(类有两个同名的属性)
看起来像 Skaffman 的回答JAXB: how to make JAXB NOT to unmarshal empty string to 0 in the link in the description is the best option after.