XStream - 解组 - XML 中指定的类型不可见
我不久前通过 XStream 存储了一些 XML 文件,它们包含对 RandomAccessSubList 的引用,该类在包级别之外不可见,并且没有默认构造函数,因此 XStream 抛出此错误:
com.thoughtworks.xstream.converters.ConversionException: Cannot construct java.util.RandomAccessSubList as it does not have a no-args constructor : Cannot construct java.util.RandomAccessSubList as it does not have a no-args constructor
---- Debugging information ----
message : Cannot construct java.util.RandomAccessSubList as it does not have a no-args constructor
cause-exception : com.thoughtworks.xstream.converters.reflection.ObjectAccessException
cause-message : Cannot construct java.util.RandomAccessSubList as it does not have a no-args constructor*
这是 XML:
<customTimes class="java.util.RandomAccessSubList">
<l class="list">
<long>1302174300146</long>
<long>1302174305231</long>
<long>1302174310312</long>
等等。
我可以不只是为 RandomAccessSubList 编写一个转换器,因为它在 util 包之外不可见。如何告诉 XStream 忽略此属性的类,或者如何为我无法引用的类指定转换器?
提前致谢!
I have some XML files stored by XStream a while ago, and they include references to RandomAccessSubList, a class which is not visible beyond the package level and has no default constructor so XStream throws this error:
com.thoughtworks.xstream.converters.ConversionException: Cannot construct java.util.RandomAccessSubList as it does not have a no-args constructor : Cannot construct java.util.RandomAccessSubList as it does not have a no-args constructor
---- Debugging information ----
message : Cannot construct java.util.RandomAccessSubList as it does not have a no-args constructor
cause-exception : com.thoughtworks.xstream.converters.reflection.ObjectAccessException
cause-message : Cannot construct java.util.RandomAccessSubList as it does not have a no-args constructor*
and this is the XML:
<customTimes class="java.util.RandomAccessSubList">
<l class="list">
<long>1302174300146</long>
<long>1302174305231</long>
<long>1302174310312</long>
etc.
I can't just write a converter for RandomAccessSubList because it's not visible outside the util package. How can I tell XStream to ignore the class for this attribute or how can I specify a converter for a class I can't reference?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我深入了解了它 - 事实证明 xstream 应该处理该 xml (它不需要无参数构造函数),出现问题是因为我将 jdk 7 与旧版本的 xstream (1.3.1) 一起使用。请参阅此处 http://code.google.com/p/pitestrunner/issues/detail?id= 4.。回到 jdk 6 解决了这个问题(由于各种原因我无法升级)。
在我意识到我确实编写了一个适用于 RandomAccessSubList 的转换器(如果有人需要它)之前:
感谢任何为我寻找的人!
I got to the bottom of it - turns out xstream should handle that xml (it doesn't need a no-args constructor), the issue arose because I was using jdk 7 with an older version of xstream (1.3.1). See here http://code.google.com/p/pitestrunner/issues/detail?id=4. Moving back to jdk 6 fixed the issue (for various reasons i can't upgrade).
Before I realised that I did write a converter that worked for RandomAccessSubList if anyone needs it:
Thanks to anyone who was looking into for me!