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

1

20

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.

Ganymede answered 16/3, 2016 at 10:28 Comment(0)
E
49

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.

Emissivity answered 16/3, 2016 at 11:9 Comment(3)
While explaining JAXB you have mentioned that "API and not an implementation", what is the difference? API is Application programming interface where you have some implementations and it is open for other programs to use it. So How can it be different from implementation? I am same as the OP, new to Java Web development world. Please enlighten us. Thx.Aldaaldan
Few mins later... I read this "Jersey-media-moxy - as you mentioned, Jersey is an implementation of JAX-RS" - As Jersey is an implementation of JAX-RS, then is JAX-RS an API (Which is some simple classes/interface)?Aldaaldan
@user3705478 An API by itself is only a specification, meaning interfaces are created to define the rules for programs to follow in order to make use of the API's intended functionality. So your understanding is correct in that JAX-RS is an API and Jersey (as well as RESTEasy and Apache CXF) is the implementation of that specification.Blackmail

© 2022 - 2024 — McMap. All rights reserved.