@XmlRootElement is an annotation that people are used to using with JAXB (JSR-222). It's purpose is to uniquely associate a root element with a class. Since JAXB classes map to complex types, it is possible for a class to correspond to multiple root elements. In this case @XmlRootElement can not be used and people start getting a bit confused. In this post I'll demonstrate how @XmlElementDecl can be used to map this use case.
July 31, 2012
JAXB and Root Elements
Labels:
JAXB,
JAXBIntrospector,
XmlElementDecl,
XmlRootElement
July 30, 2012
JAXB - No Annotations Required
There appears to be a misconception that annotations are required on the model in order to use a JAXB (JSR-222) implementation. The truth is that JAXB is configuration by exception, so annotations are only required when you want to override default behaviour. In this example I'll demonstrate how to use JAXB without providing any metadata.
June 27, 2012
EclipseLink 2.4 Release Available for Download
On behalf of the MOXy JAXB committers (great job by all), I am very proud to announce that EclipseLink 2.4 has been released and is available for download. In this post I will summarize what is new in the MOXy component:
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.
Labels:
EclipseLink,
EclipseLink 2.4,
Extension,
JAX-RS,
JSON,
MOXy,
REST
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:
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.
Labels:
EclipseLink,
EclipseLink 2.4,
Extension,
JAXB,
JSON,
Mapping File,
MOXy
April 17, 2012
Creating a RESTful Web Service - Part 2/5 (XML Metadata)
Java Persistence Architecture (JPA) is the Java EE standard for mapping POJOs to a relational database. In this example we will use JPA to interact with our database data we set up in part 1. In the previous post we specified the mapping metadata as annotations. This post will demonstrate how to specify the same metadata as XML. One advantage of specifying the metadata as XML is that the domain objects will not have a dependency on the JPA APIs. This is useful if we want to use the same domain classes on the client side.
- Part 1 - The Database
- Part 2 - Mapping the Database to JPA Entities
- Part 3 - Mapping JPA entities to XML (using JAXB)
- Part 4 - The RESTful Service
- Part 5 - The Client
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.
April 5, 2012
JAXB and Unmapped Properties
JAXB (JSR-222) is configuration by exception, meaning that there is a default mapping applied to domain objects. This means that sometimes you need to explicitly exclude a field/property. In this post I'll discuss how this can be done using @XmlTransient or @XmlAccessorType(XmlAccessType.NONE) and when each option is appropriate.
Labels:
JAXB,
XmlAccessorType,
XmlAccessType,
XmlTransient
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.
Labels:
EclipseLink,
EclipseLink 2.4,
Extension,
JAX-RS,
JAXB,
JSON,
MOXy,
REST
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
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.
Labels:
EclipseLink,
EclipseLink 2.4,
Extension,
JAX-RS,
JAXB,
JSON,
MOXy,
REST
Subscribe to:
Posts (Atom)