What is the relationship between Jersey, JAXB, JAX-RS, Moxy, Jackson, EclipseLink Moxy, json and xml?

I come from the background of Node.js and am well versed in RESTful web services.

Now I'm trying to create RESTful web services using Java. I understand basic Java, but completely new to Java-based web development.

I came to the conclusion after some lessons that I need to use the Jersey framework to create my RESTful API. I understand that Jersey is a kind of reference implementation of JAX-RS.

But I don't understand the relationship between various other terms and components, such as JAXB, Jackson, EclipseLink Moxy, jersey-media-moxy, Jettison, JSON-P JSON, XML, etc. that my readings encounter. The only thing I could conclude was not as straightforward as JavaScript to have hidden Java objects in XML or the JSON equivalent.

My question is, what is the relationship between these terms mentioned above and how they fit together if I develop a Java-based RESTful API.

+5
source share
1 answer

There are many terminologies in the Java world, and this can create a significant learning curve for new developers. It is not that it is especially difficult to transmit JSON or XML documents using Java, it is simply that the various bits and fragments you need to do have expired terminology over the years. I tried to list my understanding of the terms that you used below ...

XML - you know what XML is, do you? Extensible markup language. This is what we had before JSON has become a big thing.

JSON - oh, well, JSON is a new big thing. This is a user-friendly format for serializing objects, less verbose than XML. Very popular these days. This is a new magic bullet, good for what excites you, will solve all your problems ...

JAXB - The "Java architecture for XML binding" in the Java ecosystem is the primary mechanism for converting XML data into objects that you can interact with and vice versa. It's important to understand that this is an API, not an implementation, so it basically 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, the reference implementation is included in the Glassfish application server. Most application servers will have some JAXB implementation.

Jackson is a data binding library. It supports both XML and JSON as document formats and implements the JAXB API. You can use Jackson as your JAXB implementation, or you can just use the Jackson API directly.

EclipseLink Moxy is an alternative implementation of the JAXB API. Like Jackson, he also has his own API. You can use it or not. You probably don't want to use both Jackson and Moxy.

Jersey-media-moxy - as you mentioned, Jersey is an implementation of JAX-RS. One aspect of JAX-RS passes documents around - often XML or JSON. To do this, Jersey needs to know which library to use for data binding or stream processing. Thus, jersey-media-moxy exists as a kind of jersey plugin dependency that you can use to configure Jersey to use Moxy for your serialization purposes. There is an equivalent package for using jackson called jersey-media-json-jackson.

Jettison - Another serialization library for converting Java objects to Json and vice versa.

JSON-P - An API for handling JSON either as an event stream or by binding data to an object. This API is still under development. You may ask how this happens when someone processes json without it - the answer is that they either use their own library APIs (for example, Jackson or Moxy), or they use a library that converts the JAXB API to work with JSON (Jackson definitely resolves this, I'm not sure about Moxy). JSON-P will simplify working directly with JSON functions without all the XML concepts that JAXB contributes.

+25
source

Source: https://habr.com/ru/post/1245152/


All Articles