Showing posts with label JSON. Show all posts
Showing posts with label JSON. Show all posts

July 24, 2013

EclipseLink MOXy and the Java API for JSON Processing - Object Model APIs

The Java API for JSON Processing (JSR-353) is the Java standard for producing and consuming JSON which was introduced as part of Java EE 7.  JSR-353 includes object (DOM like) and stream (StAX like) APIs.  In this post I will demonstrate the initial JSR-353 support we have added to MOXy's JSON binding in EclipseLink 2.6.  You can now use MOXy to marshal to:
  • javax.json.JsonArrayBuilder
  • javax.json.JsonObjectBuilder
 And unmarshal from:
  • javax.json.JsonStructure
  • javax.json.JsonObject
  • javax.json.JsonArray

You can try this out today using a nightly build of EclipseLink 2.6.0:

The JSR-353 reference implementation is available here:

July 12, 2013

Oracle WebLogic 12.1.2 Now With EclipseLink MOXy JSON-Binding

Oracle WebLogic 12.1.2 is now available.  WebLogic 12.1.2 contains EclipseLink 2.4.2, this means that for the first time EclipseLink MOXy's JSON-binding is available in WebLogic out of the box.  I will demonstrate the benefits of using MOXy for JSON-binding with an example.

June 19, 2013

MOXy's @XmlVariableNode - Using a Map's Key as the Node Name

People often ask me how they can map a java.util.Map such that the keys become the node names.  In this post I will demonstrate how this can be done using the new Variable Node mapping that we have added in EclipseLink MOXy.

You can try this out today using a nightly build of EclipseLink 2.6.0:

June 17, 2013

MOXy's @XmlVariableNode - JSON Schema Example

We are in the process of adding the ability to generate a JSON Schema from your domain model to EclipseLink MOXy.  To accomplish this we have created a new Variable Node mapping. In this post I will demonstrate the new mapping by mapping a Java model to a JSON Schema.

You can try this out today using a nightly build of EclipseLink 2.6.0:

June 12, 2013

MOXy is the New Default JSON-Binding Provider in GlassFish 4

GlassFish 4 is now available offering the complete Java EE 7 (JSR-342) platform.  EclipseLink made some major contributions to this release.  The first is providing the JPA 2.1 (JSR-338) implementation.  The second which I'll cover in this post is EclipseLink MOXy is now the default JSON-binding provider for JAX-RS applications.

April 12, 2013

Customizing EclipseLink JPA-RS Messages with MOXy

In a previous post I covered how EclipseLink JPA-RS can be used to expose a JPA persistence unit as a RESTful service.  In that example we interacted with the default message formats.  Since JPA-RS leverages MOXy for its XML and JSON binding we can use MOXy to customize the messages.  In this post I will demonstrate how this is done.

Introducing EclipseLink JPA-RS

In a previous series of posts I covered how to create a JAX-RS service that leveraged JPA for the persistence layer.  EclipseLink contains a component called JPA-RS that can be used to easily and automatically expose a persistence unit as RESTful service (that supports XML and JSON messages).  MOXy provides the XML and JSON-binding for JPA-RS and things like bidirectional mappings are automatically mapped for you.  In another post I cover how MOXy can be used to customize the messages shown in this example.

I will use the JPA model that I created in the posts below:

April 8, 2013

Java API for JSON Processing (JSR-353) - Stream APIs

Java will soon have a standard set of APIs for processing JSON as part of Java EE 7.  This standard is being defined as JSR 353 - Java API for JSON Processing (JSON-P) and it is currently at the Final Approval Ballot.  JSON-P offers both object oriented and stream based approaches, in this post I will introduce the stream APIs.

You can get JSON-P reference implementation from the link below:
UPDATE

JSR-353 has passed the final approval ballot.

April 5, 2013

MOXy and JSON with Padding

JSON with padding is a communication mechanism used in JavaScript to overcome restrictions due to the same origin policy (for more information see: http://en.wikipedia.org/wiki/JSONP).  In this post I will demonstrate how to leverage JSON with padding when using MOXy as your JSON provider.

This functionality is new in EclipseLink 2.5.0 (and 2.4.2), you can try it out today using a nightly build available from:

March 26, 2013

MOXy's Object Graphs - Input/Output Partial Models to XML & JSON

Suppose you have a domain model that you want to expose as a RESTful service.  The problem is you only want to input/output part of your data.  Previously you would have created a separate model representing  the subset and then have code to move data between the models.  In EclipseLink 2.5.0 we have a new feature called Object Graphs that enables you to easily define partial views on your model.

You can try this out today by downloading an EclipseLink 2.5.0 nightly download starting on March 24, 2013 from:

March 15, 2013

Binding to JSON & XML - Handling Collections

One of EclipseLink JAXB (MOXy)'s strengths is the ability to map an object model to both JSON and XML with a single set of metadata.  The one weakness had been that you needed to compromise on the JSON key or XML element for collection properties.  I'm happy to say that this issue has been solved in EclipseLink 2.5 (and EclipseLink 2.4.2), and I will demonstrate below with an example.

You can try this out today by downloading an EclipseLink 2.5.0 (or EclipseLink 2.4.2) nightly build starting on March 15, 2013 from:

March 3, 2013

MOXy's @XmlInverseReference is now Truly Bidirectional

EclipseLink JAXB (MOXy)'s @XmlInverseReference annotation enables you to map a back pointer during the unmarshal operation (useful when mapping JPA entities).  The problem was it acted like @XmlTransient during the marshal operation.  This means that previously it could only be used in one direction.  Now I'm happy to announce in EclipseLink 2.5.0 we have expanded @XmlInverseReference so that the corresponding property may be writeable enabling it to be used in both directions.

You can try this out today by downloading one EclipseLink 2.5.0 nightly downloads starting on March 1, 2013 from:

May 25, 2012

MOXy as Your JAX-RS JSON Provider - MOXyJsonProvider

In a previous post I demonstrated how you can implement a MessageBodyReader/MessageBodyWriter to leverage  EclipseLink JAXB (MOXy)'s JSON binding in a JAX-RS service.   MOXy now includes an implementation (MOXyJsonProvider) that can be used directly or extended to make the integration even easier.

April 18, 2012

Extending JAXB - Representing Metadata as JSON

In previous posts I have described the XML mapping document and JSON-binding extensions in EclipseLink JAXB (MOXy).   Since MOXy has a JAXB model for its mapping document we were able to eat our own dog food, and now MOXy offers a JSON mapping document.

An external metadata representation is useful when:
  • You cannot modify the domain model (it may come from a 3rd party).
  • You do not want to introduce compile dependencies on JAXB APIs (if you are using a version of Java prior to Java SE 6).
  • You want to apply multiple JAXB mappings to a domain model (you are limited to one representation with annotations).
  • Your object model already contains so many annotations from other technologies that adding more would make the class unreadable.

April 16, 2012

Binding to JSON & XML - Handling Null

In a previous post I demonstrated how EclipseLink MOXy can be leveraged to produce both XML and JSON representations of your domain model.  The same metadata is used for both representations and MOXy applies it to leverage the capabilities of the media type.  In this post I'll focus on how null is handled in each of these representations.

March 15, 2012

MOXy as Your JAX-RS JSON Provider - Client Side

Recently I posted how to leverage EclipseLink JAXB (MOXy)'s JSON binding to create a RESTful service.  In this post I will demonstrate how easy it is to take advantage of MOXy's JSON binding on the client side.

March 13, 2012

MOXy as Your JAX-RS JSON Provider - Server Side

In a previous series of posts I covered how EclipseLink JAXB (MOXy) can be leveraged to create a RESTful data access service.  In this post I will cover how easy it is to leverage MOXy's JSON binding on the server side to add support for JSON messages based on JAXB mappings.
UPDATE
MOXy now includes an implementation of MessageBodyReader/MessageBodyWriter to make it even easier to leverage MOXy's JSON binding in a JAX-RS application.

August 19, 2011

Binding to JSON & XML - Geocode Example

In a previous post I introduced the JSON binding that was added in the MOXy component in EclipseLink 2.4.  In that post I explained how the same metadata that is used for XML binding can be directly applied to JSON binding.  In this post I will demonstrate how powerful this is, by mapping one object model to both XML and JSON using the same set of metadata.  Google Maps Geocoding API V2 will be used to provide the XML and JSON inputs for this example.

You can try this out now using a download available from:

August 15, 2011

JSON Binding with EclipseLink MOXy - Twitter Example

In a previous post I described how the Jettison library could be used with any JAXB implementation (Metro, MOXy, JaxMe, etc) to produce/consume JSON.  Now I'll demonstrate the native object-to-JSON binding MOXy JAXB introduced in EclipseLink 2.4.  With MOXy as your JAXB provider you can produce/consume JSON using the standard JAXB APIs (available in Java SE 6) without adding any compile time dependencies.

You can try this out now using a download available from:

April 15, 2011

JAXB and JSON via Jettison - Namespace Example

In a previous post I described how Jettison can be leveraged by a JAXB implementation to produce/consume JSON.  A reader correctly pointed out that I did not describe how to handle namespaces.  Since JSON does not support namespaces you would not normally include them in your mappings.  However if you wanted to map your object model to both JSON and XML with namespaces, this post will demonstrate how it can be done.