Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differentiating the Jersey, Jackson, and JaxB APIs

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 ?

like image 247
jayunit100 Avatar asked Dec 10 '11 21:12

jayunit100


People also ask

What is the difference between Jackson and JAXB?

JAXB converts XML to java objects, and Jackson converts the same java objects to JSON.

Does Jackson use JAXB?

With XML module Jackson provides support for JAXB (javax. xml. bind) annotations as an alternative to native Jackson annotations, so it is possible to reuse existing data beans that are created with JAXB to read and write XMLs.

What is the difference between JAX-RS and Jersey?

JAX-RS is a specification (which basically tells what to implement/follow) and Jersey is an implementation (which means how those specifications should be implemented). We can have multiple implementations for a Specification.

Does Jersey use Jackson?

Jersey uses Jackson internally to convert Java objects to JSON and vice versa.


2 Answers

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.

like image 73
StaxMan Avatar answered Oct 13 '22 13:10

StaxMan


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.

like image 28
Bill Avatar answered Oct 13 '22 13:10

Bill