I am trying to covert an xml to object using xstream:-
def convert(xml: String) = {
val xstream = new XStream(new DomDriver)
val convertedMap:testing = xstream.fromXML(xml).asInstanceOf[testing];
convertedMap
}
val justtest:String = "<testing><note>5</note></testing>"
convert(justtest)
The testing class has been defined as follows:-
class testing {
private var note = None;
}
I am getting the following error:-
java.lang.InstantiationError: testing
at sun.reflect.GeneratedSerializationConstructorAccessor28.newInstance(sum.sc)
at java.lang.reflect.Constructor.newInstance(sum.sc:419)
at com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider.newInstance(sum.sc:71)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.instantiateNewInstance(sum.sc:424)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(sum.sc:229)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(sum.sc:68)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(sum.sc:61)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(sum.sc:62)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(sum.sc:46)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(sum.sc:130)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(sum.sc:28)
at com.thoughtworks.xstream.XStream.unmarshal(sum.sc:1054)
at com.thoughtworks.xstream.XStream.unmarshal(sum.sc:1038)
at com.thoughtworks.xstream.XStream.fromXML(sum.sc:909)
at com.thoughtworks.xstream.XStream.fromXML(sum.sc:900)
at #worksheet#.convert(sum.sc:26)
at #worksheet#.#worksheet#(sum.sc:30)
Please help with the above.
Also is there a way to directly convert the xml into a map in scala?
class testing(note:String) { def getNote = note; }but i get error on calling convertedMap.getNotejava.lang.NoSuchMethodError: testing.getNote()Ljava/lang/String; at #worksheet#.convert(sum.sc:26) at #worksheet#.#worksheet#(sum.sc:29)