I’m reading the tutorial about configuring JSON for RESTful web services:
https://blogs.oracle.com/enterprisetechtips/entry/configuring_json_for_restful_web
JAXB defines how Java objects are converted from and to XML.
However I don’t understand why we have to JAXB bean model when creating RESTful web services that return JSON response? After all it is JSON not XML, right?
Short Answer
You don’t have to use JAXB to create a RESTful service using a JAX-RS framework. JAX-RS provides the
MessageBodyReader/MessageBodyWritermechanism to plug-in whatever binding you want. JSON binding providers often include an implementation of these classes that you can use directly. Below is an example of how to do this with EclipseLink MOXy (I’m the tech lead):Advantage of Using JAXB
Applying a JAXB mapping provides an easy mechanism to provide one set of mappings to get both an XML and JSON representation of your data.