我正在使用castor 1.3.3-rc1,並且我一直對此問題感到困惑。已經閱讀手冊幾次,我相信我所做的一切,在這裏,但我不斷收到:解組使用castor的對象列表給出java.lang.IllegalArgumentException:對象不是聲明類的實例
java.lang.IllegalArgumentException: object is not an instance of declaring class{File: [not available]; line: 4; column: 43}
解組我的XML時。
這是我的java類:
public class ReportConfiguration {
private List<ColumnMapping> columnMappings;
// getters and setters omitted
}
public class ColumnMapping {
private int index;
private String label;
private String sumTotal;
// getters and setters omitted
}
。這是將上述
<reportConfiguration>
<columnMappings>
<columnMapping index="0" label="Login"/>
<columnMapping index="1" label="Group"/>
<columnMapping index="2" label="Profit" sumTotal="yes"/>
</columnMappings>
</reportConfiguration>
解組到Java類我的XML數據文件,這是我的蓖麻映射文件
<mapping>
<class name="my.company.ReportConfiguration">
<map-to xml="reportConfiguration"/>
<field name="columnMappings" collection="arraylist" type="my.company.ColumnMapping">
<bind-xml name="columnMappings"/>
</field>
</class>
<class name="my.company.ColumnMapping">
<map-to xml="columnMapping"/>
<field name="index" type="integer" required="true">
<bind-xml name="index" node="attribute"/>
</field>
<field name="label" type="string" required="true">
<bind-xml name="label" node="attribute"/>
</field>
<field name="sumTotal" type="string">
<bind-xml name="sumTotal" node="attribute"/>
</field>
</class>
</mapping>
我使用了Spring OXM,在我的appli上創建了一個org.springframework.oxm.castor.CastorMarshaller實例並創建一個Unmarshaller實例作爲依賴關係。當解組我只是做這樣的事情:
ReportConfiguration config = (ReportConfiguration) unmarshaller.unmarshall(new StreamSource(inputStream));
誰能發現我做了什麼錯了/我還能怎麼調試這個問題?
非常感謝:)這節省了我的一天:) – 2013-09-20 21:19:20