Array Conversion in Xstream Parser

Posted by Avidev9 on Stack Overflow See other posts from Stack Overflow or by Avidev9
Published on 2012-12-09T16:46:19Z Indexed on 2012/12/09 17:03 UTC
Read the original article Hit count: 198

Filed under:
|
|

Hi am trying to convert the following xml into object using Xstream parser. I tried using the below code to convert the xml but am getting

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

The Code I used

xstream.alias("DebitsWSDS", GCSFeesResponse.DebitsWSDS.class);
            xstream.alias("ERRORS", GCSFeesResponse.ERRORS.class);



            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);

            GCSFeesResponse.DebitsWSDS gcsFeesResponse =(GCSFeesResponse.DebitsWSDS)xstream.fromXML(result.get_any()[0].getAsString());

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>

My class structure.

package com.avidev9.Fees;

import java.util.List;

public class GCSFeesResponse {
    public DebitsWSDS DebitsWSDS;

    public class DebitsWSDS {
        public List<ERRORS> ERRORS;
        public String xmlns;
        public DEBITS DEBITS;
    }

    public class ERRORS {
        public String TABLE_NAME;
        public Integer TABLE_ID;
        public Integer ERROR_ID;
        public Integer ROW_ID;
        public String ERROR_TEXT;
        public Integer ERROR_CODE;
        public String COLUMN_ID;
        public String ERROR_TYPE;
    }

    public class DEBITS {
        public String EFFECTIVE_DATE;
        public String ACTIVE_FLAG;
        public Long ACCOUNT_ID;
        public String DEBIT_AUTHORIZED_BY;
        public Integer DAY_OF_MONTH;
        public Integer DEBIT_ID;
        public String MEMO;
        public Integer REMAINING_OCCURRENCES;
        public String DEBIT_TYPE;
        public Integer OCCURS_NUM;
        public Integer DEBIT_AMOUNT;
        public String DEBIT_AUTHORIZED;
        public String MODIFIED_BY;
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about Xml