Folks,
I've taken over a chunk of code that uses Castor, and I've been writing
some unit tests to make sure I understand how it works.
This bit of code keeps throwing an exception:
Writer writer = new FileWriter(testFile);
Marshaller marshaller = new Marshaller(writer);
String str = "Blah";
marshaller.marshal(str);
writer.close();
Reader reader = new FileReader(testFile);
Unmarshaller unmarshaller = new Unmarshaller(String.class);
String str2 = (String)unmarshaller.unmarshal(reader);
reader.close();
Here's the exception:
Illegal Text data found as child of: string
value: "Blah"
Illegal Text data found as child of: string
value: "Blah"
org.xml.sax.SAXException: Illegal Text data found as child of: string
value: "Blah"
at
org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:842)
at
org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:1076)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:657)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:565)
at org.lockss.state.TestCastor.testString(TestCastor.java:70)
at org.lockss.test.LockssTestCase.runBare(LockssTestCase.java:213)
Where TestCastor.java:70 correspondes to the call to the unmarshaller.
Here's what the XML file looked like:
<?xml version="1.0" encoding="UTF-8"?>
<string>Blah</string>
I had thought that Castor could marshall and unmarshall many of the
basic java objects (like Strings) by default (ie, without mapping files
or any thing else). Am I using it incorrectly?
Thanks for any help you can give,
Tom
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user