Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I am coming from Node.js background and have quite a good understanding of RESTful web services.

Now I am trying to build RESTful web services using Java. I understand core Java but completely new to Java based web development.

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.

But I fail to understand relationship between various other terms and components like JAXB, Jackson, 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.

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.

like image 463
Harshal Patil Avatar asked Mar 16 '16 10:03

Harshal Patil


People also ask

Does Jersey uses jackson?

Jackson as the JSON provider in Jersey We can include jersey-media-json-jackson to enable Jackson as the JSON provider in the Jersey application.

What is EclipseLink MOXy?

The EclipseLink MOXy component enables Java developers to efficiently bind Java classes to XML or JSON. MOXy implements JAXB as well as SDO standards allowing developers to provide their mapping information through annotations as well as providing support for storing the mappings in XML format.

What is MOXy JSON?

MOXy is the default JSON-Binding Provider in Jersey 2. Though I still personally prefer Jackson over MOXy for performance reasons. Table of Contents MOXy maven dependencies/changes REST API code Model bean changes Manually adding MoxyJsonFeature Customize behavior using MoxyJsonConfig Demo.

How do I get JSON request in Jersey?

if you want your json as an Vote object then simple use @RequestBody Vote body in your mathod argument , Spring will automatically convert your Json in Vote Object.


1 Answers

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

XML - you know what XML is, right? The extensible markup language. It's what we had before JSON became the big thing.

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

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.

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

EclipseLink Moxy - an alternative implementation of the JAXB API. Like Jackson, it also has its own API. You can choose to 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 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 jackson called jersey-media-json-jackson.

Jettison - Yet Another serialisation library for converting Java objects to Json and back.

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 Jackson or Moxy) or they use a library which repurposes the JAXB API to work with JSON (Jackson 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.

like image 155
sisyphus Avatar answered Oct 21 '22 07:10

sisyphus