Java XStream 库的现代替代品?

发布于 2024-11-10 11:43:55 字数 141 浏览 5 评论 0 原文

我很多年前使用过 XStream,但我发现这些库自 2008 年以来就没有更新过(最新消息)。现在是否有更现代、最新的 Java XML 序列化库?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

卖梦商人 2024-11-17 11:43:55

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

JAXB

访问 < a href="http://jaxb.java.net/" rel="nofollow noreferrer">JAXB 项目站点 查看教程指南
另请参阅原始的 JAXB 架构白皮书

上面列出的 JAXB 项目是 API 的参考实现,由 GlassFish 应用服务器打包。

EclipseLinkMOXy

访问 EclipseLink 项目站点并阅读这篇 InfoQ 上的 EclipseLink 介绍文章,并参阅 布莱斯Doughan 关于 MOXy 的回答

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

XStream

是的,XStream,因为它实际上是 更新于2011 年,有一个重大更新和 2 个服务版本,因为您提出了要求,所以它看起来维护良好,并且是 成熟项目。不要忘记检查版本 1.4.x 中的新增功能。

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

XmlBeans

访问 XmlBeans 项目的站点

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

JiBX

访问 JiBX 项目站点,遵循教程指南

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

In order of preference, relevancy and activity:

JAXB

Visit the JAXB project's site to check out the tutorial and guide.
Have also a look at the original JAXB architecture whitepaper.

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

EclipseLink's MOXy

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

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

XStream

Yes, XStream, because it's actually been updated in 2011 with a major update and 2 service releases since 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.

Visit the XStream project's site and its tutorial to compare.

XmlBeans

Visit the XmlBeans project's site.

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

JiBX

Visit the JiBX project's site, follow the tutorial and guide.

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

同展鸳鸯锦 2024-11-17 11:43:55

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

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

  • 客户请求 - 无论您的库有多好,您的用户群都会有改进建议和功能请求。
  • 行业发展 - 模块化部署是当前的热门话题,在过去几年中,必须对 EclipseLink 进行更改以使其与 OSGi 兼容。
  • 新的 Java 版本 - Java SE 7 即将发布,虽然这并不需要发布,但我们确实需要在即将发布的版本中进行一些调整以确保兼容。此外,随着时间的推移,将会添加更多功能来利用新的 Java 方面(EclipseLink 至少需要 Java SE 5)。

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


JAXB (JSR-222)

JAXB 不仅仅是一个实现,它是通过 Java Community Process (JCP) 开发的标准。对象到 XML 库的参与者包括 XML Beans (BEA)、EMF (IBM)、TopLink (Oracle) 等。由于 JAXB 是 Java EE 的一部分,因此可在每个应用程序服务器中使用:WebLogic、GlassFish、 WebSphere、JBoss 等

JAXB 提供:

  • 100% 模式覆盖
  • 多种实现:MetroEclipseLink MOXy, Apache JaxMe
  • 包含在 Java SE 6 中,与 JDK 1.5 兼容
  • 能够从 XML 模式或 Java 类启动
  • 各种扩展机制,包括 XmlAdapter - 示例
  • 通过 Binder 保留 XML 信息集的选项 - 示例
  • JAX-WS(Web 服务)的绑定层
  • JAX-RS(Rest)的绑定层 - 示例
  • 与 JSON 兼容(与库一起使用时例如 Jettison) - 示例

EclipseLink JAXB (MOXy)

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

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

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

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

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

映射 JPA 实体的扩展

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


比较

下面是我对 JAXB 进行的一些比较XStream 和简单:

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

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).

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


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 Offers:

  • 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

EclipseLink JAXB (MOXy)

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

True Object to XML Mapping by Leveraging XPath

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

Mapping File for Handling 3rd Party Classes

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:

Extensions for Mapping JPA Entities

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:


Comparisons

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

一笔一画续写前缘 2024-11-17 11:43:55

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

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

寻找库的替代品可能是个好主意,特别是当您需要现有库不提供的功能时。但仅仅因为该库最近没有更新就寻找替代方案是不明智的。如果 XStream 满足您的需要,请坚持使用。更新并不一定意味着更好。


1 - ...最初提出问题时。


更新 - 2023

自 2011 年以来,XStream 每年至少接收一次新版本更新。请参阅 < a href="http://x-stream.github.io/changes.html" rel="nofollow noreferrer">更改 页面了解详细信息,并查看 该项目的 Github 存储库。截至目前,XStream 未被维护的理论(IMO)已被彻底揭穿

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

Another possible 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.

Looking for alternatives to a library can be a good idea, especially if you need features that the existing library doesn't provide. But simply looking for an alternative because the library hasn't been updated recently is not wise. If XStream does what you need, stick with it. Newer doesn't necessarily mean better.


1 - ... when the question was originally asked.


UPDATE - 2023

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

幸福丶如此 2024-11-17 11:43:55

XStream 非常好并且它能很好地完成它的工作。即使对于最近的项目,我也更喜欢在适合的用例中使用 XStream,因为它易于使用、轻量级且性能非常好。

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

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.

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/

独孤求败 2024-11-17 11:43:55

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

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

昨迟人 2024-11-17 11:43:55

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

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

勿忘初心 2024-11-17 11:43:55

另一种选择是 EasyML (http://github.com/cordisvictor/easyml-lib/ )。
支持 Java 8、11、17、21+。

比 XStream 更快。

XStream 也在 GitHub 上进行维护。

An alternative is EasyML (http://github.com/cordisvictor/easyml-lib/).
Supports Java 8, 11, 17, 21+.

Faster than XStream.

XStream is also being maintained on GitHub.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文