How to avoid com.thoughtworks.xstream.io.StreamException: Cannot create XmlPullParser while deseriliazation?
Solution 1
I added xpp3_min-1.1.4c.jar
in place of xpp3_min-1.1.4.jar
.My program started working
Solution 2
The underlying issue that is not reported in the stacktrace is that there is a missing resource in xstream 1.4.8
You can detect it only if you attach 1.4.9 source code (1.4.8 source code is strangely not available) and debug.
The real error that is never shown is
caused by: org.xmlpull.v1.XmlPullParserException: resource not found: /META-INF/services/org.xmlpull.v1.XmlPullParserFactory make sure that parser implementing XmlPull API is available; nested exception is:
org.xmlpull.v1.XmlPullParserException: resource not found: /META-INF/services/org.xmlpull.v1.XmlPullParserFactory make sure that parser implementing XmlPull API is available
at org.xmlpull.v1.XmlPullParserFactory.newInstance(XmlPullParserFactory.java:278)
at org.xmlpull.v1.XmlPullParserFactory.newInstance(XmlPullParserFactory.java:259)
at com.thoughtworks.xstream.io.xml.XppDriver.createParser(XppDriver.java:57)
at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1061)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1052)
at tudelft.mmi.pn.duo.core.DUOModel.loadFromXml(DUOModel.java:289)
at tudelft.mmi.pn.duo.core.DUOModel.getNewDUOModel(DUOModel.java:182)
at domaineditor.extduomodel.ExtDuoModel.<init>(ExtDuoModel.java:56)
at domaineditor.actions.OpenFile.actionPerformed(OpenFile.java:34)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at com.apple.laf.AquaMenuItemUI.doClick(AquaMenuItemUI.java:157)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
The real underlying issue seems to be this (known) issue
https://issues.apache.org/jira/browse/SMX4-581
Rajesh Kumar Dash
Developer based out from Bangalore .Have expertise with java,Eclipse Rcp,Emf,Data Engineering,Rest ApI Have some experience with Javascript front end development
Updated on June 28, 2022Comments
-
Rajesh Kumar Dash almost 2 years
I am getting a exception"Exception in thread "main" com.thoughtworks.xstream.io.StreamException: Cannot create XmlPullParser" while deserializing the xml . I have added following dependency
xmlpull_1_0_5.jar xpp3_min-1.1.4.jar xstream-1.4.8.jar
Test code:
import java.util.AbstractMap; import java.util.HashMap; import java.util.Map; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; public class Test { public static void main(String[] args) { Map<String, String> map = new HashMap<String, String>(); map.put("name", "chris"); map.put("island", "faranga"); XStream magicApi = new XStream(); magicApi.registerConverter(new MapEntryConverter()); magicApi.alias("root", Map.class); String xml = magicApi.toXML(map); System.out.println("Result of tweaked XStream toXml()"); System.out.println(xml); magicApi.fromXML(xml); // assert extractedMap.get("name").equals("chris"); // assert extractedMap.get("island").equals("faranga"); } public static class MapEntryConverter implements Converter { public boolean canConvert(Class clazz) { return AbstractMap.class.isAssignableFrom(clazz); } public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) { AbstractMap map = (AbstractMap) value; for (Object obj : map.entrySet()) { Map.Entry entry = (Map.Entry) obj; writer.startNode(entry.getKey().toString()); Object val = entry.getValue(); if (null != val) { writer.setValue(val.toString()); } writer.endNode(); } } public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Map<String, String> map = new HashMap<String, String>(); while (reader.hasMoreChildren()) { reader.moveDown(); String key = reader.getNodeName(); // nodeName aka element's name String value = reader.getValue(); map.put(key, value); reader.moveUp(); } return map; } } }
Am i misiing some dependency .Any help On this will be appreciated.
-
Paramvir Singh Karwal almost 8 yearsThoughtworks should add proper message indicating the real issue. It helps in resolving it. Above jar solved the issue.
-
rghome over 7 yearsI would recommend you pull-in from the referenced link some further information on how to resolve the problem.