De-Serializing xml with a generic XML wrapper

View: New views
5 Messages — Rating Filter:   Alert me  

De-Serializing xml with a generic XML wrapper

by dudleygb :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi guys...pls help with some pointers.

I got an XML file as such:
=========================

<?xml version="1.0" encoding="UTF-8"?>
<EE_DATA>
  <sourceSystem>BankMaster</sourceSystem>
  <messageType>BLOCK:RESPONSE</messageType>
  <messageId>77073</messageId>
  <timeStamp>2009-09-09 12:24:09.124350000</timeStamp>
  <trackingId>OT090908ZM0103123</trackingId>
  <correlationId>77073</correlationId>
  <countryISO>ZM</countryISO>
  <payload>![CDATA[
                               
    <error>
      <errorCode>7005</errorCode>
      <errorDescription>7005 | Error opening file %1</errorDescription>
    </error>
                        ]]
  </payload>
</EE_DATA>

The EE_DATA tags up to and including countryISO tag is going to be the same for every message I recieve. Instead of duplicating those tags for every different payload class I create, is there any way of instructing XStream to parse the payload tags, with a generic/reusable EE_DATA object?

Here are my classes I'm trying to deserialize to, but its resulting in a ClassCastException.
==================================================================

@XStreamAlias("payload")
public class BlockFundsResponsePayload extends EEXMLWrapper {

        private static final long serialVersionUID = -19626619355145325L;

        private GenericResponseError error;
       
        private BlockFundsResponse blockFundsResponse;

        public GenericResponseError getError() {
                return error;
        }

        public void setError(GenericResponseError error) {
                this.error = error;
        }

        public BlockFundsResponse getBlockFundsResponse() {
                return blockFundsResponse;
        }

        public void setBlockFundsResponse(BlockFundsResponse blockFundsResponse) {
                this.blockFundsResponse = blockFundsResponse;
        }

       
}
=====================================================AND

@XStreamAlias("EE_DATA")
public class EEXMLWrapper extends BaseObject {

        private static final long serialVersionUID = -3800917823750014319L;

        private String sourceSystem;
       
        private String messageType;
       
        private String messageId;
       
        private String timeStamp;
       
        private String trackingId;
       
        private String correlationId;
       
        private String countryISO;
       
        private String payload;
       

        public EEXMLWrapper() {
                super();

        }


        public String getSourceSystem() {
                return sourceSystem;
        }


        public void setSourceSystem(String sourceSystem) {
                this.sourceSystem = sourceSystem;
        }


        public String getMessageType() {
                return messageType;
        }


        public void setMessageType(String messageType) {
                this.messageType = messageType;
        }


        public String getMessageId() {
                return messageId;
        }


        public void setMessageId(String messageId) {
                this.messageId = messageId;
        }


        public String getTimeStamp() {
                return timeStamp;
        }


        public void setTimeStamp(String timeStamp) {
                this.timeStamp = timeStamp;
        }


        public String getTrackingId() {
                return trackingId;
        }


        public void setTrackingId(String trackingId) {
                this.trackingId = trackingId;
        }


        public String getCorrelationId() {
                return correlationId;
        }


        public void setCorrelationId(String correlationId) {
                this.correlationId = correlationId;
        }


        public String getCountryISO() {
                return countryISO;
        }


        public void setCountryISO(String countryISO) {
                this.countryISO = countryISO;
        }


        public String getPayload() {
                return payload;
        }


        public void setPayload(String payload) {
                this.payload = payload;
        }
       
}

Re: De-Serializing xml with a generic XML wrapper

by Jörg Schaible-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

dudleygb wrote:

>
> Hi guys...pls help with some pointers.
>
> I got an XML file as such:
> =========================
>
> <?xml version="1.0" encoding="UTF-8"?>
> <EE_DATA>
>   <sourceSystem>BankMaster</sourceSystem>
>   <messageType>BLOCK:RESPONSE</messageType>
>   <messageId>77073</messageId>
>   <timeStamp>2009-09-09 12:24:09.124350000</timeStamp>
>   <trackingId>OT090908ZM0103123</trackingId>
>   <correlationId>77073</correlationId>
>   <countryISO>ZM</countryISO>
>   <payload>![CDATA[
>
>     <error>
>       <errorCode>7005</errorCode>
>       <errorDescription>7005 | Error opening file %1</errorDescription>
>     </error>
> ]]
>   </payload>
> </EE_DATA>
>
> The EE_DATA tags up to and including countryISO tag is going to be the
> same for every message I recieve. Instead of duplicating those tags for
> every different payload class I create, is there any way of instructing
> XStream to parse the payload tags, with a generic/reusable EE_DATA object?

I'm not sure I understand your use case. Do you have multiple payload tags
in your XML or do you mean that you have several XML files and the only
difference is the payload element with the CDATA section? What do you refer
with "payload" - the complete XML or only the tag and its value in the XML
above?

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: De-Serializing xml with a generic XML wrapper

by dudleygb :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jörg,

Thank u for the response.
Yes correct, I have several different XML's and the only thing thats different for each one is whats inside the payload. I'd like to know if theres a way to apply the generic EE_DATA wrapper deserialization, for each different payload. In a nutshell, just have one EE_DATA POJO, that can be applied to different payload types.

For now, i am just doing it in two seperate steps. Parsing the EE_DATA tags, except the payload and just parsing the payload tag seperately. Just wondering if there was a way I could do it in a more generic way.


Jörg Schaible-2 wrote:
Hi,

dudleygb wrote:

>
> Hi guys...pls help with some pointers.
>
> I got an XML file as such:
> =========================
>
> <?xml version="1.0" encoding="UTF-8"?>
> <EE_DATA>
>   <sourceSystem>BankMaster</sourceSystem>
>   <messageType>BLOCK:RESPONSE</messageType>
>   <messageId>77073</messageId>
>   <timeStamp>2009-09-09 12:24:09.124350000</timeStamp>
>   <trackingId>OT090908ZM0103123</trackingId>
>   <correlationId>77073</correlationId>
>   <countryISO>ZM</countryISO>
>   <payload>![CDATA[
>
>     <error>
>       <errorCode>7005</errorCode>
>       <errorDescription>7005 | Error opening file %1</errorDescription>
>     </error>
> ]]
>   </payload>
> </EE_DATA>
>
> The EE_DATA tags up to and including countryISO tag is going to be the
> same for every message I recieve. Instead of duplicating those tags for
> every different payload class I create, is there any way of instructing
> XStream to parse the payload tags, with a generic/reusable EE_DATA object?

I'm not sure I understand your use case. Do you have multiple payload tags
in your XML or do you mean that you have several XML files and the only
difference is the payload element with the CDATA section? What do you refer
with "payload" - the complete XML or only the tag and its value in the XML
above?

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Re: De-Serializing xml with a generic XML wrapper

by dudleygb :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

cool, it was easy enough, XStream recogonises inheritance etc, so here is my payload using the generic xml wrapper. EEXMLWrapper doesnt have any XStream tags. So for any payload using the generic wrapper, just extend. Its almost like i had it in my original request above, just changed the Xstream tags around a bit.
Hope it helps someone else out there :)

package com.standardbank.eebridge.model.accounting;

import com.thoughtworks.xstream.annotations.XStreamAlias;

@XStreamAlias("EE_DATA")
public class BlockFundsResponseParent extends EEXMLWrapper  {
       
        private static final long serialVersionUID = 3396986515045400725L;
       
        private BlockFundsResponsePayload payload;

        public BlockFundsResponsePayload getPayload() {
                return payload;
        }

        public void setPayload(BlockFundsResponsePayload payload) {
                this.payload = payload;
        }

}


Hi Jörg,

Thank u for the response.
Yes correct, I have several different XML's and the only thing thats different for each one is whats inside the payload. I'd like to know if theres a way to apply the generic EE_DATA wrapper deserialization, for each different payload. In a nutshell, just have one EE_DATA POJO, that can be applied to different payload types.

For now, i am just doing it in two seperate steps. Parsing the EE_DATA tags, except the payload and just parsing the payload tag seperately. Just wondering if there was a way I could do it in a more generic way.


Jörg Schaible-2 wrote:
Hi,

dudleygb wrote:

>
> Hi guys...pls help with some pointers.
>
> I got an XML file as such:
> =========================
>
> <?xml version="1.0" encoding="UTF-8"?>
> <EE_DATA>
>   <sourceSystem>BankMaster</sourceSystem>
>   <messageType>BLOCK:RESPONSE</messageType>
>   <messageId>77073</messageId>
>   <timeStamp>2009-09-09 12:24:09.124350000</timeStamp>
>   <trackingId>OT090908ZM0103123</trackingId>
>   <correlationId>77073</correlationId>
>   <countryISO>ZM</countryISO>
>   <payload>![CDATA[
>
>     <error>
>       <errorCode>7005</errorCode>
>       <errorDescription>7005 | Error opening file %1</errorDescription>
>     </error>
> ]]
>   </payload>
> </EE_DATA>
>
> The EE_DATA tags up to and including countryISO tag is going to be the
> same for every message I recieve. Instead of duplicating those tags for
> every different payload class I create, is there any way of instructing
> XStream to parse the payload tags, with a generic/reusable EE_DATA object?

I'm not sure I understand your use case. Do you have multiple payload tags
in your XML or do you mean that you have several XML files and the only
difference is the payload element with the CDATA section? What do you refer
with "payload" - the complete XML or only the tag and its value in the XML
above?

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: De-Serializing xml with a generic XML wrapper

by Jörg Schaible-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

dudleygb wrote:

>
> cool, it was easy enough, XStream recogonises inheritance etc, so here is
> my payload using the generic xml wrapper. EEXMLWrapper doesnt have any
> XStream tags. So for any payload using the generic wrapper, just extend.
> Its almost like i had it in my original request above, just changed the
> Xstream tags around a bit.

Fine :)

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email