【发布时间】:2018-07-08 05:27:02
【问题描述】:
我正在使用 Jaxb-api 版本 2.2.5 将 xml 字符串转换为 java 对象。
这是我的 XML 示例:
<tag:TAG xmlns:tag="xxxxxxxx/tag" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="xxxxxxxx/tag RCARRVAL.xsd">
<tag:home>
<tag:home_001>01</tag:home_001>
<tag:home_002>0032</tag:home_002>
<tag:home_003>1977</tag:home_003>
<tag:home_004>4</tag:home_004>
<tag:home_005>4</tag:home_005>
<tag:home_010>2017-12-31</tag:home_010>
<tag:home_999>RG01</tag:home_999>
</tag:home>
</tag:TAG>
这是我的对象:
@XmlRootElement(name="tag:home")
@XmlAccessorType(XmlAccessType.FIELD)
public class Customer {
protected Date dateDebut;
@XmlElement(name="tag:home_003")
public Date getDateDebut() {
return dateDebut;
}
public void setDateDebut(Date dateDebut) {
this.dateDebut = dateDebut;
}
}
这是我的例外 但这在我遇到一些问题时不起作用/即使我将 @XmlElement(name="tag:home_003") 放在 gettter 或 setter 上
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
La classe comporte deux propriétés du même nom ("dateDebut")
this problem is related to the following location:
at public java.util.Date fr.models.Customer.getDateDebut()
at fr.models.Customer
this problem is related to the following location:
at protected java.util.Date fr.models.Customer.dateDebut
at fr.models.Customer
【问题讨论】:
-
你能分享完整的
Customer类吗? -
它是同一个类,只有一个字段来测试从 xml 到 java 对象的转换,就像许多教程一样
-
我不这么认为,请查看异常堆栈,
r.models.Customer.dateDebut或我们只能看到homeDate的 sared 类。 -
啊是的,这是一个拼写错误,我更改了类字段:) 抱歉
-
你能复制/粘贴你的课程吗?异常说
La classe comporte deux propriétés du même nom ("homeDate")并且客户类中没有homeDate属性。