I am trying to deserialize a string in Java using the XStream package. The XStream package can serialize my class. I get XML (I can’t change the XML format) from the server and try to save its node information in the appropriate variables in a specific class. My function is at the bottom, and I tried to register a new converter for the XStream object (assuming that this is because one variable is an array of bytes), but still no luck. Can anyone shed light on these exceptions? Do I need to register "MyClass" and write my own converter for XStream to deserialize my class? Thanks in advance.
Exception if a string or StringReader is passed from XML () as input:
[Fatal error]: 1: 1: Content is not allowed in the prolog.
com.thoughtworks.xstream.io.StreamException: Content is not allowed in the prolog.
at com.thoughtworks.xstream.io.xml.DomDriver.createReader (DomDriver.java:86)
at com.thoughtworks.xstream.io.xml.DomDriver.createReader (DomDriver.java:66)
at com.thoughtworks.xstream.XStream .fromXML (XStream.java:853)
Exception if ByteArrayInputStream is used as input fromXML ():
com.thoughtworks.xstream.converters.ConversionException: ByteSize: ByteSize: ByteSize: ByteSize
---- Debug information ---- message: ByteSize: ByteSize
reason-exception: com.thoughtworks.xstream.mapper.CannotResolveClassException
reason-message: ByteSize : ByteSize
class: MyClass
type required: MyClass
path: / MyClass / ByteSize
on com.thoughtworks.xstream.core.TreeUnmarshaller.convert (TreeUnmarshaller.java:89)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert (AbstractReferenceUnmarshaller : 63)
on com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother (TreeUnmarshaller.java:76)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert and another (TreeUnmarshaller.java:60)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start (TreeUnmarshaller.java:137)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrate. unmarshal (AbstractTreeMarshallingStrategy.java:33)
at com.thoughtworks.xstream.XStream.unmarshal (XStream.java:923)
at com.thoughtworks.xstream.XStream.unmarshal (XStream.java:909)
at com.thoughtworks.xstream.XStream .fromXML (XStream.java:861)
static Object fromXmlString(String xml)
{
XStream xStream = new XStream(new DomDriver());
xStream.registerConverter(new EncodedByteArrayConverter());
return xStream.fromXML(xml);
}
Ken
source
share