Found the issue by adding the following:
Marshaller.setMarshalListener (new MyListener());
...
static class MyListener implements MarshalListener {
        public boolean preMarshal(Object arg0) {
                getLog().debug("Marshalling
"+arg0.getClass().getName());
                return true;
        }
        public void postMarshal(Object arg0) {
        }
}

The log file will tell you the object type that causes the problem right
before throwing the exception below.  So then I added in code that when
it was time to marshal that object type, make necessary adjustments to
the instance field that was causing the serialization issue.  In this
case it was an uninitialized char field that had some bad data.

Thanks,
  Dan C.

-----Original Message-----
From: Chapman, Daniel [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 17, 2005 11:11 AM
To: [email protected]
Subject: [castor-user] XML Marshalling IOTException invalid XML
character

Hello,
I'm using the basic marshal call to marshal a considerably large
serializable object.  
Code:
try {
        // Create a File to marshal to
        writer = new FileWriter(fileName);
                
        // Marshal the entire hash.
        Marshaller marshaller = new Marshaller(writer);
        marshaller.marshal(cust);
        getLog().debug("Customer XML Saved as "+fileName);
} catch (Exception e) {
        getLog().debug("Unable to marshal customer data.", e);
} finally {
        try {writer.close();} catch (Exception e) {}
}

Exception written is:
Unable to marshal customer data.
The character ' .' is an invalid XML character
        at
org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1534)
        at
org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1854)
        at
org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1854)
        at
org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1860)
        at
org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1860)
        at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:842)
        ...
Not sure what the character above is, when I cut and paste it acts like
a carriage return..., so I think it's a non-printable character.  My
object is too large to dig in and find it myself.

What are my options?  Can I add some sort of custom handler to the
marshalling process so I can replace these chars and continue?  Or is
there a way for castor to tell me where in the object hierarchy the
problem is occurring?

Thanks in advance,
        Dan C.

-------------------------------------------------
If you wish to unsubscribe from this list, please 
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to