7

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 ?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
jayunit100
  • 17,388
  • 22
  • 92
  • 167
  • Jersey has multiple implementations, but Jackson is used for "POJO-mapping" which is the most convenient method usually. – StaxMan Dec 11 '11 at 05:08

4 Answers4

6

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.

StaxMan
  • 113,358
  • 34
  • 211
  • 239
  • So ... is jersey meant to implement REST ? Or is it an object to xml serializer ? – jayunit100 Dec 11 '11 at 14:53
  • 9
    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 Dec 11 '11 at 18:09
4

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.

Palash Jain
  • 325
  • 1
  • 7
4

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.

BillRobertson42
  • 12,602
  • 4
  • 40
  • 57
  • Thanks - what is the difference between jersey and jax B ? Im wondering where one API ends and the other begins .... – jayunit100 Dec 11 '11 at 14:52
  • 1
    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. – BillRobertson42 Dec 11 '11 at 14:59
  • 1
    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. – StaxMan Dec 11 '11 at 18:11
0

Jersey is an implementation of JAX-RS. You can think of JAX-RS as an Common interface build for RESTful Web Services. The implementation of this interface is provided by vendors. There are many implementation of this interface available like JERSEY and Rest-Easy. On the other hand Jackson is a Json Processor. It helps you in converting your objects to json and vice versa.

Yoshita Mahajan
  • 443
  • 4
  • 6