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 21, 2013

Mapping Bad XML - Enumerated Collection Elements

In a previous post I introduced EclipseLink JAXB (MOXy)'s @XmlVariableNode extension.  In this post I'll demonstrate how @XmlVariableNode could be leveraged to handle an interesting question I came across on Stack Overflow.  In that question instead of a collection being represented with an element that appeared multiple times, the element name contained the index.  While I would never recommend structuring your XML document this way sometimes you encounter it and need to be able to map it.

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.

May 28, 2013

EclipseLink 2.5 Release Available for Download

On behalf of the MOXy JAXB committers (great job by all), I am very proud to announce that EclipseLink 2.5 has been released and is available for download.  In this post I will summarize what is new in the MOXy component.  For details on the entire release see the following link:

How to Get EclipseLink 2.5

You can download the EclipseLink install from:
EclipseLink 2.5 is also available from Maven Central (see http://wiki.eclipse.org/EclipseLink/Maven):
<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>org.eclipse.persistence.moxy</artifactId>
    <version>2.5.0</version>
 </dependency>

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 10, 2013

MOXy's Object Graphs - Handling Inheritance

In previous posts we have explored how object graphs can be defined through metadata and programatically.  In this post I'll demonstrate the impact of inheritance in your domain model on how you define object graphs.

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

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:

April 3, 2013

MOXy's Object Graphs & Dynamic JAXB

JAXB (JSR-222) makes it easy for you to convert instances of your domain classes to/from XML.  The EclipseLink MOXy implementation offers an extension called Dynamic JAXB where instead of real classes you have instances of a map like class called DynamicEntity. You can access the data on your DynamicEntity using get and set methods that take the property name (i.e. customer.get("address") and customer.set('name", "Jane Doe").

In this post, first we will bootstrap a dynamic JAXBContext based on an external mapping file.  Then we unmarshal an XML document to dynamic entities, and finally we will apply an object graph to scope the resulting JSON output.

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

March 28, 2013

MOXy's Object Graphs - Partial Models on the Fly to/from XML & JSON

In a previous post I introduced how MOXy's Object Graph feature allows you to input and output partial models.  In that example I demonstrated how to define a partial model via metadata.  In this example we will create the object graphs programmatically.  This gives you additional flexibility when you need to create one on the fly.

You can try this out today by downloading an EclipseLink 2.5.0 nightly download starting on March 24, 2013 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 6, 2013

JAXB and java.util.Map

Is it ironic that it can be difficult to map the java.util.Map class in JAXB (JSR-222)?  In this post I will cover some items that will make it much easier.

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:

February 15, 2013

Leveraging MOXy in your Web Service via JAX-WS Provider

In previous articles I demonstrated how EclipseLink JAXB (MOXy) is directly integrated into the JAX-WS implementations in WebLogic (as of 12.1.1) and in GlassFish (as of 3.1.2).  In this post I'll demonstrate how to leverage MOXy in any application server by using the JAX-WS Provider class.