Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

JSON-B Test Drive Using JAX-RS

DZone's Guide to

JSON-B Test Drive Using JAX-RS

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

· Java Zone ·
Free Resource

How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.

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!

How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.

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

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}