Java XStream 库的现代替代品?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6159047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:36:05  来源:igfitidea点击:

Modern alternative to Java XStream library?

javaxmlxstream

提问by Eli Schneider

I used XStream many years ago, but I see that the libraries is not updated since 2008 (latest news). Is there now a more modern and up to dates Java XML serialization library?

多年前我使用过 XStream,但我看到这些库自 2008 年以来没有更新(最新消息)。现在有更现代和最新的 Java XML 序列化库吗?

回答by haylem

In order of preference, relevancy and activity:

按照偏好、相关性和活动的顺序:

JAXB

JAXB

Visit the JAXB project's siteto check out the tutorialand guide. Have also a look at the original JAXB architecture whitepaper.

访问JAXB 项目的站点以查看教程指南。还可以查看原始JAXB 架构白皮书

The JAXB projet listed above is the reference implementation of the API, and is packaged in by the GlassFish Application Server.

上面列出的 JAXB 项目是 API 的参考实现,由 GlassFish Application Server 打包。

EclipseLink's MOXy

EclipseLinkMOXy

Visit the EclipseLink project's siteand read this introductory article to EclipseLink on InfoQ, and see Blaise Doughan's answer about MOXy.

访问EclipseLink 项目的站点并阅读InfoQ 上 EclipseLink 的这篇介绍性文章,并查看Blaise Doughan 对 MOXy 的回答

EclipseLink originated from Oracle's TopLinkand is now open source, managed by the Eclipse Foundation, and used in a number of Eclipse-based products.

EclipseLink 源自 Oracle 的TopLink,现在是开源的,由Eclipse Foundation管理,并用于许多基于 Eclipse 的产品中。

XStream

流媒体

Yes, XStream, because it's actually been updated in 2011 with a major update and 2 service releasessince you asked, so it seems well-maintained and a pretty good contender used by mature projects. Don't forget to check what's new in version 1.4.x.

是的,XStream,因为自从您提出要求以来,它实际上在 2011 年进行了一次重大更新和 2 个服务版本的更新,因此它似乎维护良好,并且是成熟项目使用的一个很好的竞争者。不要忘记检查版本 1.4.x 中的新内容。

Visit the XStream project's siteand its tutorialto compare.

访问XStream 项目的站点及其教程进行比较。

XmlBeans

XmlBeans

Visit the XmlBeans project's site.

访问XmlBeans 项目的站点

XmlBeans is a well-tested project that has been around for a while.

XmlBeans 是一个经过充分测试的项目,已经存在一段时间了。

JiBX

吉宝信

Visit the JiBX project's site, follow the tutorialand guide.

访问JiBX 项目的站点,按照教程指南进行操作

JiBX might be a simpler alternative if you don't like the complexity of XmlBeans or even JAXB.

如果您不喜欢 XmlBeans 甚至 JAXB 的复杂性,JiBX 可能是一个更简单的选择。

回答by bdoughan

Note:I'm the EclipseLink JAXB (MOXy)lead, and a member of the JAXB (JSR-222) expert group.

注意:我是EclipseLink JAXB (MOXy) 的负责人,也是 JAXB ( JSR-222) 专家组的成员。

You are correct in considering a libraries release frequency when making a software choice. There are many reasons for a new product release:

在选择软件时考虑库的发布频率是正确的。新产品发布的原因有很多:

  • Customer Requests- No matter how good your library is, your user base will have improvement suggestions and feature requests.
  • Industry Developments- Modular deployment is hot topic right now, over the past few years changes had to be made to EclipseLink to make it compatible with OSGi.
  • New Java Versions- Java SE 7 will be released soon, while this does not necessitate a release we did need to make some tweaks in our upcoming release to ensure we were compatible. Also over time more features will be added to leverage new Java aspects (EclipseLink requires a minimum of Java SE 5).
  • 客户请求- 无论您的库有多好,您的用户群都会有改进建议和功能请求。
  • 行业发展- 模块化部署是目前的热门话题,在过去几年中,必须对 EclipseLink 进行更改以使其与 OSGi 兼容。
  • 新的 Java 版本- Java SE 7 将很快发布,虽然这不需要发布,但我们确实需要在即将发布的版本中进行一些调整以确保我们兼容。此外,随着时间的推移,将添加更多功能以利用新的 Java 方面(EclipseLink 至少需要 Java SE 5)。

Another important aspect of evaluating any open source project is the number of active committers. Sites like ohloh.netare useful for that:

评估任何开源项目的另一个重要方面是活跃提交者的数量。ohloh.net 之类的网站对此很有用:



JAXB (JSR-222)

JAXB (JSR-222)

JAXB is more than an implementation, it is a standard that is developed through the Java Community Process (JCP). There have been participants from such object-to-XML libraries as XML Beans (BEA), EMF (IBM), TopLink (Oracle), etc. Because JAXB is part of Java EE it is available in every application server: WebLogic, GlassFish, WebSphere, JBoss, etc.

JAXB 不仅仅是一个实现,它还是一个通过 Java Community Process (JCP) 开发的标准。已经有来自 XML Beans (BEA)、EMF (IBM)、TopLink (Oracle) 等对象到 XML 库的参与者。因为 JAXB 是 Java EE 的一部分,所以它可用于每个应用服务器:WebLogic、GlassFish、 WebSphere、JBoss 等

JAXB Offers:

JAXB 优惠:

  • 100% schema coverage
  • Multiple implementations: Metro, EclipseLink MOXy, Apache JaxMe, etc
  • Included in Java SE 6, compatible with JDK 1.5
  • Ability to start from XML schema or Java classes
  • Various extension mechanisms including XmlAdapter - Example
  • Option to preserve XML infoset via Binder - Example
  • Binding layer for JAX-WS (Web Services)
  • Binding layer for JAX-RS (Rest) - Example
  • Compatible with JSON (when used with libraries such as Jettison) - Example
  • 100% 模式覆盖
  • 多种实现:MetroEclipseLink MOXyApache JaxMe
  • 包含在 Java SE 6 中,与 JDK 1.5 兼容
  • 能够从 XML 模式或 Java 类开始
  • 包括 XmlAdapter 在内的各种扩展机制 -示例
  • 通过 Binder 保留 XML 信息集的选项 -示例
  • JAX-WS(Web 服务)的绑定层
  • JAX-RS (Rest) 的绑定层 -示例
  • 与 JSON 兼容(与 Jettison 等库一起使用时) -示例


EclipseLink JAXB (MOXy)

EclipseLink JAXB (MOXy)

MOXy is a JAXB implementation that offers many useful extensions, including:

MOXy 是一个 JAXB 实现,它提供了许多有用的扩展,包括:

True Object to XML Mapping by Leveraging XPath

通过利用 XPath 实现真正的对象到 XML 的映射

XPath based mapping allows you to start with both Java classes and an XML schema and map the two together.

基于 XPath 的映射允许您从 Java 类和 XML 模式开始,并将两者映射到一起。

Mapping File for Handling 3rd Party Classes

用于处理第 3 方类的映射文件

In the current JAXB spec the metadata is supplied via annotations. This can be problematic to use with 3rd party classes that cannot be modified. This is why MOXy offers a way to specify the mappings via XML:

在当前的 JAXB 规范中,元数据是通过注解提供的。这在与无法修改的 3rd 方类一起使用时可能会出现问题。这就是为什么 MOXy 提供了一种通过 XML 指定映射的方法:

Extensions for Mapping JPA Entities

映射 JPA 实体的扩展

Often times you need to do more with your Java objects then just map then to XML. You may also need to persist them to a database. This means your object model may have additional constraints on it that you need to account for. MOXy offers a number of extensions for this kind of use case:

很多时候,您需要对 Java 对象执行更多操作,然后只需映射到 XML。您可能还需要将它们保存到数据库中。这意味着您的对象模型可能有您需要考虑的其他约束。MOXy 为这种用例提供​​了许多扩展:



Comparisons

比较

Below are a couple comparisons I have done comparing JAXB to XStream and Simple:

下面是我所做的一些比较,将 JAXB 与 XStream 和 Simple 进行了比较:

回答by Stephen C

The fact that something hasn't been updated for 3 years doesn't mean that it is out of date. It might simply mean that there has been no needto update it. If there is no need to change a project, why change it?

某些内容 3 年未更新的事实并不意味着它已过时。这可能只是意味着不需要更新它。如果不需要改变一个项目,为什么要改变它?

Another explanation for the apparent lack of "progress" is that changing library APIs tends to be disruptive to projects that depend on them. This is particularly problematic for projects that combine lots of third-party components and libraries into one Java application.

明显缺乏“进展”的另一种解释是,更改库 API 往往会破坏依赖它们的项目。对于将许多第三方组件和库组合到一个 Java 应用程序中的项目来说,这尤其成问题。



Looking for alternatives to a library is a good thing, but simply doing this because the library hasn't been updated recently is not. If XStream does what you need, stick with it. Newer doesn't necessarily mean better.

寻找图书馆的替代品是一件好事,但仅仅因为图书馆最近没有更新就这样做不是。如果 XStream 满足您的需求,请坚持下去。更新并不一定意味着更好。



UPDATE - 2019

更新 - 2019

XStream has been receiving updates with a new release at least once a year since 2011. Refer to the Changespage for details, and look at the activity on the Github repositoryfor the project. As of now, the theory that XStream is not being maintained is (IMO) thoroughly debunked.

自 2011 年以来,XStream 每年至少接收一次新版本的更新。有关详细信息,请参阅更改页面,并查看该项目的Github 存储库上的活动。到目前为止,XStream 没有得到维护的理论已经被 (IMO) 彻底揭穿了。

回答by Yohan Liyanage

XStream is pretty good and it does it's job well. Even for recent projects, I prefer to use XStream for use cases where it fits because it's easy to use, lightweight, and performs really well.

XStream 非常好,它的工作做得很好。即使对于最近的项目,我更喜欢将 XStream 用于它适合的用例,因为它易于使用、重量轻且性能非常好。

If you are looking at some serious bean-binding work, take a look at Simple Framework. It's also a good tool. This helped me out in one project where I needed to do some serious custom mapping work with annotations. http://simple.sourceforge.net/

如果您正在研究一些严肃的 bean 绑定工作,请查看 Simple Framework。这也是一个很好的工具。这帮助我完成了一个项目,在该项目中我需要使用注释进行一些严肃的自定义映射工作。http://simple.sourceforge.net/

回答by cuttcards

XStream 1.4.6 was released in Dec 2013, with Java 8 improvements, so the library HAS been updated since 2008.

XStream 1.4.6 于 2013 年 12 月发布,对 Java 8 进行了改进,因此该库自 2008 年以来已更新。

回答by Valentyn Kolesnikov

Underscore-javacan read and write xml files. I am the maintainer of the project. Java 11+ is supported.

Underscore-java可以读写 xml 文件。我是项目的维护者。支持 Java 11+。