您正在尝试使用Xstream解析器将以下xml转换为对象。 我尝试使用下面的代码来转换xml,但我正在
Duplicate field ERRORS
---- Debugging information ----
field : ERRORS
class : com.avidev9.Fees.GCSFeesResponse$DebitsWSDS
required-type : com.avidev9.Fees.GCSFeesResponse$DebitsWSDS
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /DebitsWSDS/ERRORS[2]
line number : 1
version : null
我使用的代码
xstream.alias("DebitsWSDS", DebitsWSDS.class);
xstream.alias("DEBITS", DebitsWSDS.DEBITS.class);
xstream.alias("list", DebitsWSDS.class);
xstream.addImplicitCollection(DebitsWSDS.class, "ERRORS");
xstream.alias("ERROR_ID", String.class);
xstream.alias("TABLE_NAME", String.class);
xstream.alias("TABLE_ID", String.class);
xstream.alias("ROW_ID", String.class);
xstream.alias("ERROR_TEXT", String.class);
xstream.alias("ERROR_CODE", String.class);
xstream.alias("COLUMN_ID", String.class);
xstream.alias("ERROR_TYPE", String.class);
XML
<DebitsWSDS xmlns="">
<DEBITS>
<DEBIT_ID>-1</DEBIT_ID>
<ACCOUNT_ID>12321312313</ACCOUNT_ID>
<EFFECTIVE_DATE>2012-12-12T00:00:00-06:00</EFFECTIVE_DATE>
<DAY_OF_MONTH>12</DAY_OF_MONTH>
<DEBIT_TYPE>S</DEBIT_TYPE>
<OCCURS_NUM>1</OCCURS_NUM>
<DEBIT_AMOUNT>750</DEBIT_AMOUNT>
<MEMO>S</MEMO>
<ACTIVE_FLAG>Y</ACTIVE_FLAG>
<MODIFIED_BY/>
<DEBIT_AUTHORIZED/>
<DEBIT_AUTHORIZED_BY/>
<REMAINING_OCCURRENCES>0</REMAINING_OCCURRENCES>
</DEBITS>
<ERRORS>
<ERROR_ID>1</ERROR_ID>
<TABLE_NAME>Debits</TABLE_NAME>
<TABLE_ID>-1</TABLE_ID>
<ROW_ID>0</ROW_ID>
<COLUMN_ID>EXCEPTION</COLUMN_ID>
<ERROR_TYPE>E</ERROR_TYPE>
<ERROR_CODE>4</ERROR_CODE>
<ERROR_TEXT>This debit type is not allowed for this company and policy group</ERROR_TEXT>
</ERRORS>
<ERRORS>
<ERROR_ID>2</ERROR_ID>
<TABLE_NAME>Clients</TABLE_NAME>
<TABLE_ID/>
<ROW_ID>0</ROW_ID>
<COLUMN_ID>CLOSE_SCHED_DATE</COLUMN_ID>
<ERROR_TYPE>E</ERROR_TYPE>
<ERROR_CODE>4</ERROR_CODE>
<ERROR_TEXT>Client has been closed. Cannot Authorize Draft.</ERROR_TEXT>
</ERRORS>
<ERRORS>
<ERROR_ID>3</ERROR_ID>
<TABLE_NAME>Debits</TABLE_NAME>
<TABLE_ID>-1</TABLE_ID>
<ROW_ID>0</ROW_ID>
<COLUMN_ID>EXCEPTION</COLUMN_ID>
<ERROR_TYPE>E</ERROR_TYPE>
<ERROR_CODE>4</ERROR_CODE>
<ERROR_TEXT>Cannot Schedule a Debit or Draft. Client has been closed.</ERROR_TEXT>
</ERRORS>
<ERRORS>
<ERROR_ID>1</ERROR_ID>
<TABLE_NAME>Debits</TABLE_NAME>
<TABLE_ID>-1</TABLE_ID>
<ROW_ID>0</ROW_ID>
<COLUMN_ID>ACTIVE_FLAG</COLUMN_ID>
<ERROR_TYPE>W</ERROR_TYPE>
<ERROR_CODE>4</ERROR_CODE>
<ERROR_TEXT>Creating debit on inactive Client account.</ERROR_TEXT>
</ERRORS>
</DebitsWSDS>
我的班级结构。
package com.avidev9.Fees;
import java.util.List;
public class DebitsWSDS {
public List<ERROR> ERRORS;
public DEBITS DEBITS;
public class ERROR {
public String TABLE_NAME;
public String TABLE_ID;
public String ERROR_ID;
public String ROW_ID;
public String ERROR_TEXT;
public String ERROR_CODE;
public String COLUMN_ID;
public String ERROR_TYPE;
}
public class DEBITS {
public String EFFECTIVE_DATE;
public String ACTIVE_FLAG;
public String ACCOUNT_ID;
public String DEBIT_AUTHORIZED_BY;
public String DAY_OF_MONTH;
public String DEBIT_ID;
public String MEMO;
public String REMAINING_OCCURRENCES;
public String DEBIT_TYPE;
public String OCCURS_NUM;
public String DEBIT_AMOUNT;
public String DEBIT_AUTHORIZED;
public String MODIFIED_BY;
}
}
答案 0 :(得分:0)
通过xstream处理List有点棘手。您需要为部分
添加implicitCoolectionxstream.alias("list", ERRORS.class);
xstream.addImplicitCollection(ERRORS.class, "ERRORS");
希望这会有所帮助!!
答案 1 :(得分:0)
在Class中,您有String和Integer Variable的组合。但是在使用别名()时,你只提到了String.class
。
您应该将所有变量声明为String并尝试运行代码。