SimpleXml 框架 - 嵌入式集合
我尝试使用 simple 来序列化嵌入式集合。 例如:
Map<String, List<MyClass>>
我已经在 MyClass 中添加了必要的注释,我尝试使用 @ElementMap 但它不起作用: 线程“main”中的异常org.simpleframework.xml.transform.TransformException:不支持类java.util.ArrayList的转换
如果它
@ElementMap Map<String, MyClass>
工作正常。我不知道如何处理嵌入式集合。我了解 @ElementList
注释,但不知道在这种情况下如何使用它。有什么提示吗?
I try to serialize embedded collection using simple.
For example :
Map<String, List<MyClass>>
I already added necessary annotations in MyClass, i tried with @ElementMap but it doesn't work:Exception in thread "main" org.simpleframework.xml.transform.TransformException: Transform of class java.util.ArrayList not supported
If its just
@ElementMap Map<String, MyClass>
it works fine. I don't know ho to deal with embedded collection. I know about @ElementList
annotation but don't know how to use it in this case. Any hints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题。我设法让它工作的唯一方法是一个非常俗气的黑客 - 将 List 包装在另一个类中。
然后,而不是
......你会:
在我的例子中,地图对于我的类来说是完全私有的(即其他类永远不会直接与地图对话),所以事实上我在这里有这个额外的层没有太大区别。当然,生成的 XML 很糟糕,但同样,就我而言,它是可以忍受的,因为我的类之外没有任何东西正在消耗它。希望我有一个比这更好的解决方案,但目前,我很困惑。
I'm coming across the same issue. The only way I have managed to get it working has been a really cheesy hack - wrapping List in another class.
And then, instead of
...you'd have:
In my case, the Map is entirely private to my class (i.e. other classes never get to talk directly to the Map), so the fact that I have this extra layer in here doesn't make much of a difference. The XML that is produced of course, is gross, but again, in my case, it's bearable because there is nothing outside of my class that is consuming it. Wish I had a better solution than this, but at the moment, I'm stumped.