Over a million developers have joined DZone.

JSON-B Test Drive Using JAX-RS

Get the low down on the JSON-B specification included in Java EE 8.

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

This is a quick post about JSON-B specification which is due in Java EE 8. It’s main purposes are:

  • Provide JSON binding i.e. marshalling and un-marshalling to and from Java objects
  • Eclipselink will server as Reference Implementation
  • Supports Java object model to JSON mapping via annotations
  • Supports default mapping for implicit transformations b/w Java model and JSON (without annotation/additional metadata)
  • Produce JSON schema from Java classes
  • Support further customization of default mapping mechanisms as well as partial mapping (part of JSON doc needs to be mapped to Java model)
  • Will integrate with JSON-P and probably with JSON API JEP 198 (Java SE API for JSON processing) if needed

Please Note That

  • This is just a quick test of the JSON-B implementation in a Java EE 7 container
  • It not an ideal scenario, i.e. it does not demonstrate integration of the JSON-B spec with a Java EE container (at least not yet).
  • I am not aware of Java EE 8 builds which ship with JSON-B as of right now.

From a (Java EE 8) Container Integration Perspective (Near Future)

The integration should be seamless and transparent — the way it is in case of JSON-P and JAXB annotated classes, i.e. you will ideally be able to annotate your Java classes using JSON-B annotations and expect them to be serialized or deserialized automatically by the container (e.g. JAX-RS runtime).

Overview

  • Have a simple POJO
  • Expose POJO using JAX-RS (GET, POST)
  • Use JAX-RS Message Body Reader and Writer – this overrides the default JSON-P providers and leverage JSON-B API here (simply use the default mapping feature) for transformation
  • Repeat the same for a ‘List of’ POJOs

Github project available here – this is not a Maven project. Ideally, you would want to clone into NetBeans, then build and run on a Java EE 7 container. Make sure to have RI JAR in WAR (details below).

To Be Noted

  • I could not grab the Maven artifact of the JSON-B API JAR (maybe I am missing something), so ended up including the JSON-B API sources in the WAR itself.
  • Same case with the RI – download it directly from here.

What’s Really Important

  • You can grab the draft specification, API sources, and javadocs from here (the API sources itself are a part of the ZIP downloaded using this link).
  • Check out the Reference Implementation here

Cheers!

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:
java ee ,java ,maven ,netbeans ,github ,project ,specification ,jar

Published at DZone with permission of Abhishek Gupta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}