如何使用xStream输出具有List属性的Java对象?
我正在尝试将一些 Java 对象输出为 JSON,它们具有 List 属性,我希望将其格式化为 { "People" : [ { "Name" : "Bob" } , { "Name" : "Jim" } ] }
但是,我不知道如何使用 XStream 来做到这一点。它总是输出为 { "Person" : { "Name" : "Bob" }, "Person" : { "Name" : "Bob" }
有没有办法解决这个问题?如果您需要更具体的东西,我已经将一些示例代码与 github 中的单元测试放在一起: http: //gist.github.com/371358
谢谢!
I am trying to output some Java objects as JSON, they have List properties which I want to be formatted as { "People" : [ { "Name" : "Bob" } , { "Name" : "Jim" } ] }
However, I cannot figure out how to do this with XStream. It always outputs as { "Person" : { "Name" : "Bob" }, "Person" : { "Name" : "Bob" }
Is there a way to fix this? I've put together some sample code with a unit test in github if you need something more concrete to play with: http://gist.github.com/371358
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题出在列表顶部声明的 @XStreamImplicit ,删除它并尝试。它应该可以正常工作;)
/杰伊
I assume that the problem is with @XStreamImplicit which is declared on top of the List, remove that and try. It should work fine ;)
/jay