区分Jersey,Jackson和JaxB API

时间:2022-05-21 19:34:13

Hi : I've been using Jackson for JSON processing internally , and I want to serve these objects as Jsons to an external API (REST) (now, they are stored internally as java objects) .

嗨:我一直在内部使用Jackson进行JSON处理,我想将这些对象作为Jsons提供给外部API(REST)(现在,它们作为java对象存储在内部)。

The obvious implementation would be to write some kind of query engine that reads requests, retrieves objects from the underlying data store, and then serializes them into Jsons using Jackson.

显而易见的实现是编写某种查询引擎来读取请求,从底层数据存储中检索对象,然后使用Jackson将它们序列化为Jsons。

However I'm starting to realize that there are APIs that already can be used to assemble such web services , taking care of a lot of the mundane details (security, query parsing, REST coordination) . For example, it appears that jersey annotations can be used to define REST services ....

然而,我开始意识到已经有一些API已经可以用于组装这样的Web服务,它们处理了许多平凡的细节(安全性,查询解析,REST协调)。例如,似乎可以使用泽西注释来定义REST服务....

So my question is : what are the state of the art in Java EE JSON based web services, and what do these services use as data stores (I.e. Plaintext? RDBMS? Object data services?)

所以我的问题是:基于Java EE JSON的Web服务有哪些最先进的技术,以及这些服务用作数据存储的内容(即明文?RDBMS?对象数据服务?)

Most importantly... what is the functional difference between the different apis for xml and json data mapping i.e. jersey/Jackson/JaxB ?

最重要的是...... xml和json数据映射的不同apis之间的功能差异是什么,即jersey / Jackson / JaxB?

3 个解决方案

#1


4  

Aside from Jersey (and other JAX-RS impls like RESTeasy), which use Jackson, you might also benefit from using something like jDBI for binding relational data in POJOs first. It does many things bigger ORMs (like Hibernate) do, but is simpler to use for most common tasks.

除了使用Jackson的Jersey(以及像RESTeasy这样的其他JAX-RS impls)之外,您还可以从使用jDBI之类的东西中获益,首先在POJO中绑定关系数据。它做了许多更大的ORM(如Hibernate),但是对于大多数常见任务来说更简单。

Or if you prefer Hibernate, use Jackson Hibernate module to handle some edge cases there may be when reading/writing POHOs as JSON.

或者如果您更喜欢Hibernate,请使用Jackson Hibernate模块来处理读/写POHO时可能存在的边缘情况。

#2


4  

There is a plugin for Jersey that will take your JAXB annotated objects and serialize them as JSON automatically. Jersey (JAX-RS) is a really good offering.

Jersey有一个插件可以获取JAXB带注释的对象,并自动将它们序列化为JSON。泽西岛(JAX-RS)是一个非常好的产品。

You can also use JPA annotations on the same objects and a JPA provider like Eclipse Link for a lot of your database needs. A basic relational database can handle most website's needs.

您还可以在相同的对象和JPA提供程序(如Eclipse Link)上使用JPA注释,以满足您的许多数据库需求。基本关系数据库可以处理大多数网站的需求。

#3


1  

JAVA had released some specifications called JAX-RS to standardise the development of RESTfull web services using J2EE. These specifications are just the definitions and not the concrete implementation .

JAVA发布了一些名为JAX-RS的规范,以使用J2EE标准化RESTfull Web服务的开发。这些规范只是定义而不是具体实现。

There are various implementations providers of these APIs(specifications). Jersey, RestEasy, RestLet, Apache-cxf are few such implementations which can be used to implement RESTfull services in JAVA.

这些API(规范)有各种实现提供程序。 Jersey,RestEasy,RestLet,Apache-cxf是一些可用于在JAVA中实现RESTfull服务的实现。

Specifically to Jersey, It is not just limited to the implementation of the JAX-RS APIs. It is a framework which has its own set of APIs built by extending JAX-RS capabilities and provides additional capabilities to further ease the development of REST APIs in JAVA.

具体到泽西岛,它不仅限于JAX-RS API的实现。它是一个框架,它通过扩展JAX-RS功能构建了自己的一组API,并提供了进一步简化JAVA中REST API开发的附加功能。

JAXB stand for Java architecture for XML binding which is another specification provided by JAVA to marshall and unmarshall Java objects to XML and vice versa. Again, Its just the specification and not the concrete implementation.

JAXB代表用于XML绑定的Java体系结构,这是JAVA提供的另一种规范,用于将Java对象编组和解组为XML,反之亦然。同样,它只是规范而不是具体实现。

Coming to Jackson, It is just a JSON processor(typically one of the implementation of JAXB) used to marshall and unmarshall objects from Java to JSON. Jersey uses Jackson internally to convert Java objects to JSON and vice versa.

来到Jackson,它只是一个JSON处理器(通常是JAXB的一个实现),用于编组和解组从Java到JSON的对象。 Jersey在内部使用Jackson将Java对象转换为JSON,反之亦然。

#1


4  

Aside from Jersey (and other JAX-RS impls like RESTeasy), which use Jackson, you might also benefit from using something like jDBI for binding relational data in POJOs first. It does many things bigger ORMs (like Hibernate) do, but is simpler to use for most common tasks.

除了使用Jackson的Jersey(以及像RESTeasy这样的其他JAX-RS impls)之外,您还可以从使用jDBI之类的东西中获益,首先在POJO中绑定关系数据。它做了许多更大的ORM(如Hibernate),但是对于大多数常见任务来说更简单。

Or if you prefer Hibernate, use Jackson Hibernate module to handle some edge cases there may be when reading/writing POHOs as JSON.

或者如果您更喜欢Hibernate,请使用Jackson Hibernate模块来处理读/写POHO时可能存在的边缘情况。

#2


4  

There is a plugin for Jersey that will take your JAXB annotated objects and serialize them as JSON automatically. Jersey (JAX-RS) is a really good offering.

Jersey有一个插件可以获取JAXB带注释的对象,并自动将它们序列化为JSON。泽西岛(JAX-RS)是一个非常好的产品。

You can also use JPA annotations on the same objects and a JPA provider like Eclipse Link for a lot of your database needs. A basic relational database can handle most website's needs.

您还可以在相同的对象和JPA提供程序(如Eclipse Link)上使用JPA注释,以满足您的许多数据库需求。基本关系数据库可以处理大多数网站的需求。

#3


1  

JAVA had released some specifications called JAX-RS to standardise the development of RESTfull web services using J2EE. These specifications are just the definitions and not the concrete implementation .

JAVA发布了一些名为JAX-RS的规范,以使用J2EE标准化RESTfull Web服务的开发。这些规范只是定义而不是具体实现。

There are various implementations providers of these APIs(specifications). Jersey, RestEasy, RestLet, Apache-cxf are few such implementations which can be used to implement RESTfull services in JAVA.

这些API(规范)有各种实现提供程序。 Jersey,RestEasy,RestLet,Apache-cxf是一些可用于在JAVA中实现RESTfull服务的实现。

Specifically to Jersey, It is not just limited to the implementation of the JAX-RS APIs. It is a framework which has its own set of APIs built by extending JAX-RS capabilities and provides additional capabilities to further ease the development of REST APIs in JAVA.

具体到泽西岛,它不仅限于JAX-RS API的实现。它是一个框架,它通过扩展JAX-RS功能构建了自己的一组API,并提供了进一步简化JAVA中REST API开发的附加功能。

JAXB stand for Java architecture for XML binding which is another specification provided by JAVA to marshall and unmarshall Java objects to XML and vice versa. Again, Its just the specification and not the concrete implementation.

JAXB代表用于XML绑定的Java体系结构,这是JAVA提供的另一种规范,用于将Java对象编组和解组为XML,反之亦然。同样,它只是规范而不是具体实现。

Coming to Jackson, It is just a JSON processor(typically one of the implementation of JAXB) used to marshall and unmarshall objects from Java to JSON. Jersey uses Jackson internally to convert Java objects to JSON and vice versa.

来到Jackson,它只是一个JSON处理器(通常是JAXB的一个实现),用于编组和解组从Java到JSON的对象。 Jersey在内部使用Jackson将Java对象转换为JSON,反之亦然。