XStream 或简单
我需要决定使用哪一个。我的情况很简单。我需要将简单的 POJO/Bean 转换为 XML,然后再转换回来。没什么特别的。
我正在寻找的一件事是它也应该包括父属性。最好的是它可以在超级类型上工作,超级类型可以只是一个标记接口。
如果有人可以比较这两者的优缺点,以及哪一个缺少什么。我知道 XStream 也支持 JSON,这是一个优点。但是,如果我们把 JSON 放在一边,Simple 乍一看看起来更简单。 Simple 在开发和社区方面的未来是什么?我相信 XStream 非常流行,甚至“XStream”这个词也引起了很多关注。
谢谢。
I need to decide on which one to use. My case is pretty simple. I need to convert a simple POJO/Bean to XML, and then back. Nothing special.
One thing I am looking for is it should include the parent properties as well. Best would be if it can work on super type, which can be just a marker interface.
If anyone can compare these two with cons and pros, and which thing is missing in which one. I know that XStream supports JSON too, thats a plus. But Simple looked simpler in a glance, if we set JSON aside. Whats the future of Simple in terms of development and community? XStream is quite popular I believe, even the word, "XStream", hit many threads on SO.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
Simple 和 Jaxb 的一个“简单”(双关语)缺点是它们需要先对对象进行注释,然后才能将其序列化为 XML。当您快速想要使用未注释的对象序列化其他人的代码时会发生什么?如果有一天您能看到这种情况发生,XStream 会更合适。 (有时它实际上只是归结为这样的简单要求来驱动您的决策)。
One "simple" (pun intended) disadvantage of Simple and Jaxb is that they require annotating your objects before they can be serialized to XML. What happens the day you quickly want to serialize someone else's code with objects that are not annotated? If you can see that happening one day, XStream is a better fit. (Sometimes it really just boils down to simple requirements like this to drive your decisions).
在阅读 stackoverflow 时快速浏览了 simple;作为对 Paul Marshalls 有用帖子的修正,我想我应该提到 Simple 似乎确实支持通过注释进行版本控制 -
http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#version
Was taking a quick look at simple while reading stackoverflow; as an amendment to Paul Marshalls helpful post, I thought i'd mention that Simple does seem to support versioning through annotations-
http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#version
Simple 比 XStream 慢得多(将对象序列化为 xml)
http:// pronicles.blogspot.com/2011/03/xstream-vs-simple.html
Simple is much slower then XStream(in serialization objects to xml)
http://pronicles.blogspot.com/2011/03/xstream-vs-simple.html
仅通过阅读文档(我面临着与您相同的问题,但还没有尝试过任何一种方法;对此持保留态度):
XSTREAM
简单
每当类正确但版本不同时,通过不严格的解析来处理版本控制。 (即,如果自上一版本以来添加了两个字段并删除了一个字段,它将忽略删除的字段并且不会抛出异常,但不会设置添加的字段。)与 XStream 一样,它似乎没有一种将数据从一个版本迁移到下一个版本的方法,但与 XStream 不同的是,没有外部库可以介入并处理它。据推测,处理这个问题的方法是使用一些外部函数(也许是类中的“版本”变量?),所以你这样做
Stuff myRestoredStuff = serializer.read(Stuff.class, 文件);
myRestoredStuff.sanityCheck();
常用的(反)序列化调整是通过添加/编辑注释来进行的,但如果您需要做一些模糊的事情,则支持编写自己的(反)序列化函数来覆盖标准方法。
Just from reading the documentation (I'm facing down the same problem you are, but haven't tried either way yet; take this with a grain of salt):
XSTREAM
SIMPLE
Handles versioning by being non-strict in parsing whenever the class is right, but the version is different. (i.e., if you added two fields and removed one since the last version, it'll ignore the removed field and not throw an exception, but won't set the added fields.) Like XStream, it doesn't seem to have a way to migrate data from one version to the next, but unlike XStream, there's no external library to step in and handle it. Presumably, the way to handle this is with some external function (and maybe a "version" variable in your class?), so you do
Stuff myRestoredStuff = serializer.read(Stuff.class, file);
myRestoredStuff.sanityCheck();
Commonly-used (de)serializing adjustments are made by adding/editing annotations, but there's support for writing your own (de)serialization functions to override the standard methods if you need to do something woolly.
为什么不使用 JAXB 来代替呢?
有用的资源:
Why not use JAXB instead?
Useful resources:
我建议您看一下 Simple
I'd recommend that you take a look at Simple
我还建议Simple,看看Simple。 net/download/stream/doc/tutorial/tutorial.php" rel="nofollow noreferrer">教程,在那里自己决定。邮件列表反应非常灵敏,您将始终得到任何疑问的及时答复。
I would also suggest Simple, take a look at the tutorial, there and decide for yourself. The mailing list is very responsive and you will always get a prompt answer to any queries.
到目前为止我还没有使用过 Simple 框架。
根据我使用 Xstream 的经验。它在 XML 上运行良好。但是,对于 JSON,当我尝试序列化包含哈希表列表的 bean 时,结果并不像预期的那么精确。
So far I have never use Simple framework yet.
Based on my experience with Xstream. It worked well on XML. However, for JSON, the result is not as precise as expected when I attempt to serialize a bean that contain a List of Hashtable.
我想我在这里分享这个。
让 XStream 忽略缺失的字段(当您删除属性时):
这也可以扩展以处理版本和属性重命名。
感谢 Peter Voss:https://pvoss.wordpress.com/2009/01/08/ xstream
Thought I share this here.
To get XStream to ignore missing fields (when you have removed a property):
This can also be extended to handle versions and property renames.
Credit to Peter Voss: https://pvoss.wordpress.com/2009/01/08/xstream