Hi,
ich habe hier folgendes genau nach Doku von xStream geschrieben, bekomme beim serialisieren KEINE dann aber beim deserialisieren Fehler, die ich absolut nicht deuten kann.
Vielleicht kann mir Jemand auf die Sprünge helfen?
Hier mein Code:
public static void serialize(File file, Graph g) {
HashMap<String, List<String>> imageTMP = g.getImageURLmap(); HashMap<Coordinate, String> coordTMP = g.getCoordMap();
XStream xStream = new XStream(new StaxDriver());
OutputStream buff;
try {
buff = new BufferedOutputStream(new FileOutputStream(file));
OutputStreamWriter writer = new OutputStreamWriter(buff, Charset.forName(„UTF-8“));
xStream.toXML(imageTMP, writer);
xStream.toXML(coordTMP, writer);
writer.close();
}
catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();
}}@SuppressWarnings(„unchecked“) public static void deserializeImage(File file, Graph g) {
HashMap<String, List<String>> imageTMP;
HashMap<Coordinate, String> coordTMP;
XStream xStream = new XStream(new StaxDriver());
BufferedInputStream buff;
try {
buff = new BufferedInputStream(new FileInputStream(file));
InputStreamReader reader = new InputStreamReader(buff, Charset.forName(„UTF-8“));
ObjectInputStream in = xStream.createObjectInputStream(reader);
imageTMP = (HashMap<String, List<String>>:wink: in.readObject();
coordTMP = (HashMap<Coordinate, String>:wink: in.readObject(); reader.close();
}
catch (Exception e) {// TODO Auto-generated catch block e.printStackTrace();imageTMP = new HashMap<String, List<String>>();coordTMP = new HashMap<Coordinate, String>();
}
g.setImageURLmap(imageTMP);
g.setCoordMap(coordTMP);}
Dazu dann die Fehlermeldungen (mit new XStream(new StaxDriver()); sowie new XStream();
com.thoughtworks.xstream.converters.ConversionException: Cannot construct java.util.Map$Entry : java.util.Map$Entry : Cannot construct java.util.Map$Entry : java.util.Map$Entry---- Debugging information ----message : Cannot construct java.util.Map$Entry : java.util.Map$Entrycause-exception : com.thoughtworks.xstream.converters.reflection.ObjectAccessExceptioncause-message : Cannot construct java.util.Map$Entry : java.util.Map$Entryclass : java.util.Map$Entryrequired-type : java.util.Map$Entryconverter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverterpath : /entryline number : 1version : 1.4.7------------------------------- at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79) at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134) at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32) at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1185) at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1157) at com.thoughtworks.xstream.XStream$4.readFromStream(XStream.java:1851) at com.thoughtworks.xstream.core.util.CustomObjectInputStream.readObjectOverride(CustomObjectInputStream.java:120) at java.io.ObjectInputStream.readObject(Unknown Source) at org.opentripplanner.util.SeMo_Wiki.deserializeImage(SeMo_Wiki.java:255) at org.opentripplanner.graph_builder.GraphBuilderTask.run(GraphBuilderTask.java:153) at org.opentripplanner.standalone.OTPMain.main(OTPMain.java:61)Caused by: com.thoughtworks.xstream.converters.reflection.ObjectAccessException: Cannot construct java.util.Map$Entry : java.util.Map$Entry at com.thoughtworks.xstream.converters.reflection.SunLimitedUnsafeReflectionProvider.newInstance(SunLimitedUnsafeReflectionProvider.java:80) at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.instantiateNewInstance(AbstractReflectionConverter.java:553) at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:256) at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) … 13 moreCaused by: java.lang.InstantiationException: java.util.Map$Entry at sun.misc.Unsafe.allocateInstance(Native Method) at com.thoughtworks.xstream.converters.reflection.SunLimitedUnsafeReflectionProvider.newInstance(SunLimitedUnsafeReflectionProvider.java:76) … 16 more
Und mit new XStream(new DomDriver());
[Fatal Error] :127:8: Markup im Dokument nach dem Root-Element muss ordnungsgemäß formatiert sein.com.thoughtworks.xstream.io.StreamException: : Markup im Dokument nach dem Root-Element muss ordnungsgemäß formatiert sein. at com.thoughtworks.xstream.io.xml.DomDriver.createReader(DomDriver.java:105) at com.thoughtworks.xstream.io.xml.DomDriver.createReader(DomDriver.java:77) at com.thoughtworks.xstream.XStream.createObjectInputStream(XStream.java:1812) at org.opentripplanner.util.SeMo_Wiki.deserializeImage(SeMo_Wiki.java:253) at org.opentripplanner.graph_builder.GraphBuilderTask.run(GraphBuilderTask.java:153) at org.opentripplanner.standalone.OTPMain.main(OTPMain.java:61)Caused by: org.xml.sax.SAXParseException; lineNumber: 127; columnNumber: 8; Markup im Dokument nach dem Root-Element muss ordnungsgemäß formatiert sein. at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) at com.thoughtworks.xstream.io.xml.DomDriver.createReader(DomDriver.java:98) … 5 more
Irgendjemand eine Idee? Meine Vermutung wäre ja, dass es an dem „Value“ der Map „List<String>>“ liegen könnte, die als Generic interpretiert wird!?
Grüße Oekel