|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
CannotResolveClassException during object unmarshalI get the following exception while trying to unmarshal an object. |
|
|
Re: CannotResolveClassException during object unmarshalHi Alessandro,
ale.marino78@... wrote: > I get the following exception while trying to unmarshal an object. > > $ java -classpath .:junit.jar:xstream/1.3/xstream.jar > org.junit.runner.JUnitCore it.alessandro.MarshalUnmarshalXmlTestCase > JUnit version 4.5 serialized xml: **<operation_result>blah blah > ...</operation_result>** Time: 0.149 > There was 1 failure: > 1) > testUnmarshalXmlTagWithUnderscore(it.alessandro.MarshalUnmarshalXmlTestCase) > com.thoughtworks.xstream.mapper.CannotResolveClassException: > <operation_result>blah blah ...</operation_result> : > <operation_result>blah blah ...</operation_result> > at > com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:62) > at [snip] > > The code of the test case is this: > > public class MarshalUnmarshalXmlTestCase extends TestCase { > private static final XmlFriendlyReplacer XML_FRIENDLY_REPLACER = > new XmlFriendlyReplacer("§", "_"); > > public void testUnmarshalXmlTagWithUnderscore() { > String operation = "blah blah ..."; > > StringWriter s = new StringWriter(); > XStream xs = new XStream(); > xs.alias("operation_result", String.class); > xs.marshal(operation, (HierarchicalStreamWriter) new > PrettyPrintWriter(s, XML_FRIENDLY_REPLACER)); String xml = > s.toString(); System.out.println("serialized xml: **" + > xml+"**"); > > String unmarshalledOperation = (String) > xs.unmarshal((HierarchicalStreamReader) new > XppDomReader(new Xpp3Dom(xml), XML_FRIENDLY_REPLACER)); > > assertEquals(unmarshalledOperation, operation); > } > } > > I don't understand why Xstream is throwing this exception since I'm using > just a String class. Is it possible that the XmlFriendlyReplacer could > cause this exception when unmarshalling? No, you set the complete XML string as tag name of the DOM element. That's exactly what the error says, XStream cannot find a class (or alias) with the name "<operation_result>blah blah ...</operation_result>". If you want to parse XML into a Xpp3Dom you have to use the Xpp3DomBuilder. - Jörg --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
R: [xstream-user] Re: CannotResolveClassException during object unmarshalChanging the following line of the test case:
String unmarshalledOperation = (String) xs.unmarshal((HierarchicalStreamReader) new XppDomReader(new Xpp3Dom(xml), XML_FRIENDLY_REPLACER)); with this one, solved the problem: String unmarshalledOperation = (String) xs.unmarshal(new XppDomDriver(XML_FRIENDLY_REPLACER).createReader(new StringReader(xml))); Thanks, Alessandro -----Messaggio originale----- Da: news per conto di Jörg Schaible Inviato: gio 15/10/2009 23.30 A: user@... Oggetto: [xstream-user] Re: CannotResolveClassException during object unmarshal Hi Alessandro, ale.marino78@... wrote: > I get the following exception while trying to unmarshal an object. > > $ java -classpath .:junit.jar:xstream/1.3/xstream.jar > org.junit.runner.JUnitCore it.alessandro.MarshalUnmarshalXmlTestCase > JUnit version 4.5 serialized xml: **<operation_result>blah blah > ...</operation_result>** Time: 0.149 > There was 1 failure: > 1) > testUnmarshalXmlTagWithUnderscore(it.alessandro.MarshalUnmarshalXmlTestCase) > com.thoughtworks.xstream.mapper.CannotResolveClassException: > <operation_result>blah blah ...</operation_result> : > <operation_result>blah blah ...</operation_result> > at > com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:62) > at [snip] > > The code of the test case is this: > > public class MarshalUnmarshalXmlTestCase extends TestCase { > private static final XmlFriendlyReplacer XML_FRIENDLY_REPLACER = > new XmlFriendlyReplacer("§", "_"); > > public void testUnmarshalXmlTagWithUnderscore() { > String operation = "blah blah ..."; > > StringWriter s = new StringWriter(); > XStream xs = new XStream(); > xs.alias("operation_result", String.class); > xs.marshal(operation, (HierarchicalStreamWriter) new > PrettyPrintWriter(s, XML_FRIENDLY_REPLACER)); String xml = > s.toString(); System.out.println("serialized xml: **" + > xml+"**"); > > String unmarshalledOperation = (String) > xs.unmarshal((HierarchicalStreamReader) new > XppDomReader(new Xpp3Dom(xml), XML_FRIENDLY_REPLACER)); > > assertEquals(unmarshalledOperation, operation); > } > } > > I don't understand why Xstream is throwing this exception since I'm using > just a String class. Is it possible that the XmlFriendlyReplacer could > cause this exception when unmarshalling? exactly what the error says, XStream cannot find a class (or alias) with the name "<operation_result>blah blah ...</operation_result>". If you want to parse XML into a Xpp3Dom you have to use the Xpp3DomBuilder. - Jörg --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |