Differentiating the Jersey, Jackson, and JaxB APIs

18,125

Solution 1

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.

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

Solution 2

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.

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.

Solution 3

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 .

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.

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.

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.

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.

Share:
18,125
jayunit100
Author by

jayunit100

Current: Red Hat BigData, Apache BigTop commiter. Past: Phd in scalable, data driven bioinformatics analytics tools on the JVM, which led me into the world of big data as the genomic data space started to explode. After that, I was with peerindex as a hadoop mapreduce dev, and now I'm a big data engineer at redhat. We're making red hat storage awesome(r). blog: http://jayunit100.blogspot.com. github: http://github.com/jayunit100 pubs : https://www.researchgate.net/profile/Jay_Vyas/publications/?ev=prf_pubs_p2

Updated on August 16, 2022

Comments

  • jayunit100
    jayunit100 over 1 year

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

    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.

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

    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?)

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

  • jayunit100
    jayunit100 over 12 years
    Thanks - what is the difference between jersey and jax B ? Im wondering where one API ends and the other begins ....
  • jayunit100
    jayunit100 over 12 years
    So ... is jersey meant to implement REST ? Or is it an object to xml serializer ?
  • BillRobertson42
    BillRobertson42 over 12 years
    Jersey is the reference implementation of JAX-RS, a web services standard. It gives you a mechanism to dispatch http requests to your classes/methods. JAXB is a standard that lets you translate between XML and objects. Part of the JAX-RS specification allows you to simply return an object with JAXB annotations, and if you sn XML content type, it will send XML to the client based on your JAXB objects. There is a plugin for Jersey that takes the same JAXB annotated objects and produces JSON if you tell it to return JSON.
  • StaxMan
    StaxMan over 12 years
    JAX-RS is a REST framework (Java Api for Rest-like web Services), and Jersey is the JAX-RS reference implementation. Jersey uses serialization frameworks like JAXB (xml) and Jackson (json, bson, xml, csv) for actual reading/writing of content. So you can use whatever mechanism for consuming and producing data, but Jersey comes bundled with a useful set already.
  • StaxMan
    StaxMan over 12 years
    Also, you do not have to use JAXB annotations, unless you either want to use JAXB, or another package that can also use them: Jackson, for example, supports its own annotations as well as JAXB ones. But if you simply follow Bean naming convention, you typically dont need to use JAXB annotations at all.