0

您好我正在尝试使用 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;
    }

}
4

2 回答 2

0

通过 xstream 处理 List 有点棘手。您需要为部分添加implicitCoolection

xstream.alias("list", ERRORS.class);
xstream.addImplicitCollection(ERRORS.class, "ERRORS");

希望这可以帮助!!

于 2012-12-09T17:01:28.057 回答
0

在您的班级中,您有字符串和整数变量的组合。但是在使用 alias() 时,您只提到了String.class.

您应该将所有变量声明为 String 并尝试运行您的代码。

于 2012-12-09T17:20:42.813 回答