java Jersey、JAXB、JAX-RS、Moxy、Jackson、EclipseLink Moxy、json 和 xml 是什么关系?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36032978/
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
What is the relationship between Jersey, JAXB, JAX-RS, Moxy, Hymanson, EclipseLink Moxy, json and xml?
提问by Harshal Patil
I am coming from Node.js background and have quite a good understanding of RESTful web services.
我来自 Node.js 背景,对 RESTful Web 服务有很好的理解。
Now I am trying to build RESTful web services using Java. I understand core Java but completely new to Java based web development.
现在我正在尝试使用 Java 构建 RESTful Web 服务。我了解核心 Java,但对基于 Java 的 Web 开发完全陌生。
I come to conclusion after some tutorials that I need to use Jersey framework to build my RESTful API. I understand that Jersey is some sort of reference implementation of JAX-RS.
经过一些教程后,我得出结论,我需要使用 Jersey 框架来构建我的 RESTful API。我知道 Jersey 是 JAX-RS 的某种参考实现。
But I fail to understand relationship between various other terms and components like JAXB, Hymanson, EclipseLink Moxy, jersey-media-moxy, Jettison, JSON-P JSON, XML, etc.that come across my readings. The only thing that I could conclude was it is not so straight forward like JavaScript to covert Java objects into XML or JSON equivalent.
但我无法理解我的阅读中遇到的各种其他术语和组件之间的关系,例如JAXB、Hymanson、EclipseLink Moxy、jersey-media-moxy、Jettison、JSON-P JSON、XML 等。我唯一可以得出的结论是,将 Java 对象转换为 XML 或 JSON 等价物并不像 JavaScript 那样直接。
My question is what is the relationship between these terms mentioned above and how they fit together if I am developing a Java based RESTful API.
我的问题是,如果我正在开发基于 Java 的 RESTful API,上面提到的这些术语之间的关系是什么,以及它们如何组合在一起。
回答by sisyphus
There sure is a lot of terminology in the Java world and that can create a significant learning curve for new developers. It's not that it's particularly difficult to pass JSON or XML documents around using Java, it's just that the various bits and pieces you need to do it have sprouted terminology over the years. I've tried to list my understanding of the terms you've used below...
Java 世界中肯定有很多术语,它们可以为新开发人员创建一个重要的学习曲线。并不是说使用 Java 传递 JSON 或 XML 文档特别困难,只是多年来您需要做的各种零碎的术语已经出现。我试图列出我对您在下面使用的术语的理解......
XML- you know what XML is, right? The extensible markup language. It's what we had before JSON became the big thing.
XML- 您知道 XML 是什么,对吗?可扩展的标记语言。这是我们在 JSON 成为大事之前所拥有的。
JSON- oh, well, JSON is the new big thing. It's a human readable object serialisation format, less verbose than XML. Very popular nowadays. It's the new magic bullet, good for what ails ya, gonna solve all your problems...
JSON- 哦,好吧,JSON 是新的大事。它是一种人类可读的对象序列化格式,不如 XML 冗长。现在非常流行。这是新的魔法子弹,对你的病有好处,会解决你所有的问题......
JAXB- the "Java Architecture for XML Binding" in the Java ecosystem is the primary mechanism for turning XML data into objects which you can then interact with, and vice versa. It's important to realise that it's an API and not an implementation, so it mostly defines a set of annotations and simple classes / interfaces in the javax.xml.bind
package. To do anything useful with JAXB you need an implementation. There's a reference implementation included in the Glassfish application server. Most application servers will have some kind of implementation of JAXB.
JAXB- Java 生态系统中的“用于 XML 绑定的 Java 架构”是将 XML 数据转换为您可以与之交互的对象的主要机制,反之亦然。重要的是要意识到它是一个API而不是一个实现,所以它在javax.xml.bind
包中主要定义了一组注解和简单的类/接口。要使用 JAXB 做任何有用的事情,您需要一个实现。Glassfish 应用程序服务器中包含一个参考实现。大多数应用程序服务器都有某种 JAXB 实现。
Hymanson- a library for data binding. It supports both XML and JSON as document formats, and implements the JAXB API. You can use Hymanson as your implementation of JAXB, or you can just use the Hymanson API directly.
Hymanson- 用于数据绑定的库。它支持 XML 和 JSON 作为文档格式,并实现 JAXB API。您可以使用 Hymanson 作为 JAXB 的实现,也可以直接使用 Hymanson API。
EclipseLink Moxy- an alternative implementation of the JAXB API. Like Hymanson, it also has its own API. You can choose to use it, or not. You probably don't want to use both Hymanson and Moxy.
EclipseLink Moxy- JAXB API 的替代实现。和 Hymanson 一样,它也有自己的 API。您可以选择使用或不使用它。您可能不想同时使用 Hymanson 和 Moxy。
Jersey-media-moxy - as you mentioned, Jersey is an implementation of JAX-RS. One aspect of JAX-RS is passing documents around - often XML or JSON. To do that Jersey needs to know what underlying library to use for data-binding or stream processing. So jersey-media-moxy exists as a kind of jersey plugin dependency which you can use to configure Jersey to use Moxy for your object serialisation needs. There's an equivalent package for using Hymanson called jersey-media-json-Hymanson.
Jersey-media-moxy - 正如你提到的,Jersey 是 JAX-RS 的一个实现。JAX-RS 的一方面是传递文档——通常是 XML 或 JSON。为此,Jersey 需要知道用于数据绑定或流处理的底层库。因此 jersey-media-moxy 作为一种 jersey 插件依赖项存在,您可以使用它来配置 Jersey 以使用 Moxy 来满足您的对象序列化需求。有一个使用 Hymanson 的等效包,称为 jersey-media-json-Hymanson。
Jettison- Yet Another serialisation library for converting Java objects to Json and back.
Jettison- 另一个序列化库,用于将 Java 对象转换为 Json 并返回。
JSON-P- an API for processing JSON either as a stream of events or via data-binding to an object. This API is still in development. You might ask how it is that anybody does json processing without it - the answer is that they either utilise proprietary library APIs (such as Hymanson or Moxy) or they use a library which repurposes the JAXB API to work with JSON (Hymanson definitely allows this, I'm not sure about Moxy). JSON-P will make it easier to work directly with JSON features, without all the XML-concepts which JAXB brings in.
JSON-P- 一种用于将 JSON 处理为事件流或通过数据绑定到对象的 API。此 API 仍在开发中。您可能会问,如果没有它,任何人都如何进行 json 处理 - 答案是他们要么使用专有库 API(例如 Hymanson 或 Moxy),要么使用重新利用 JAXB API 来处理 JSON 的库(Hymanson 绝对允许这样做) ,我不确定 Moxy)。JSON-P 将使直接使用 JSON 特性变得更容易,而无需 JAXB 引入的所有 XML 概念。