从 Java 到 XML 序列化/反序列化的最佳实践
将 Java 类序列化为 XML 的最合适方法是什么? 我尝试了 JAXB,但它在接口和泛型方面存在问题。什么解决方案侵入性最小但可扩展?
What is the most appropriate way to serialize Java Classes to XML?
I tried JAXB, but it has issues with Interfaces and Generics. What solution is least intrusive but scalable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我一直对 XStream 有着积极的体验:
http://x-stream。 github.io/tutorial.html#to-xml
正如您所看到的,它使用起来很简单。
我实际上并没有将 XStream 与泛型一起使用(我只将它用于简单的 JavaBean 类型类),但 Google 似乎建议它可以毫无问题地处理它们。例如 http://techo-ecco.com/blog/ xstream-spring-ws-oxm-and-generics/
I've always had positive experiences with XStream:
http://x-stream.github.io/tutorial.html#to-xml
As you can see, it's simple to use.
I haven't actually used XStream with Generics (I've only ever used it for simple JavaBean type classes), but Google seems to suggest it handles them without problems. e.g. http://techo-ecco.com/blog/xstream-spring-ws-oxm-and-generics/
我建议克服 JAXB 的接口和泛型问题。
JAXB 编组和泛型
java.util.List 是一个接口,JAXB 无法处理接口
I would suggest to overcome the issues with interfaces and generics you have with JAXB.
JAXB Marshalling and Generics
java.util.List is an interface, and JAXB can't handle interfaces