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 6, 2013
JAXB and java.util.Map
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:
Labels:
EclipseLink,
EclipseLink 2.5,
JAXB,
JSON,
MOXy,
XmlInverseReference
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.
December 21, 2012
JAXB's @XmlAnyElement(lax=true) Explained
In a previous post I introduced how the @XmlAnyElement(lax=true) annotation could be used to create a very flexible mapping. In this post I'll dig a bit deeper into how it relates to both the @XmlRootElement and @XmlElementDecl.
Labels:
JAXB,
XmlAnyElement,
XmlElementDecl,
XmlRootElement
December 20, 2012
JAXB - Representing Null and Empty Collections
In this post I will cover how to differentiate between null and empty collections in the XML representation with JAXB (JSR-222).
November 15, 2012
Creating a Generic List Wrapper in JAXB
To marshal/unmarshal a list with a JAXB (JSR-222) implementation you need to create a wrapper object to hold the list. People find this onerous having to create multiple wrapper objects for this purpose. Below I'll demonstrate that in reality you only need to create one. This post is based on an answer I gave on Stack Overflow.
Labels:
Collection Property,
JAXB,
XmlAnyElement,
XmlRootElement
November 14, 2012
Using JAXB With XSLT to Produce HTML
JAXB (JSR-222) enables Java to treat a domain model as XML. In this post I will demonstrate how to leverage this by applying an XSLT stylesheet to a JAXB model to produce HTML. This approach is often leveraged when creating JAX-RS applications.
November 1, 2012
Applying a Namespace During JAXB Unmarshal
For some an XML schema is a strict set of rules for how the XML document must be structured. But for others it is a general guideline to indicate what the XML should look like. This means that sometimes people want to accept input that doesn't conform to the XML schema for some reason. In this example I will demonstrate how this can be done by leveraging a SAX XMLFilter.
October 19, 2012
Updating EclipseLink in WebLogic
JSON binding was added to EclipseLink in version 2.4. If you are using a version of that does not contain this version (i.e. WebLogic 10.3.4 (11g) contains EclipseLink 2.1.2), then by default you won't have access to this functionality. The recommended solution to this problem is to create a shared library in WebLogic for the newer release of EclipseLink.
August 16, 2012
Removing JAXBElement From Your Domain Model
JAXBElement is a JAXB (JSR-222) mechanism that stores name and namespace information in situations where this can not be determined from the value or mapping. For example in the class below the elements billing-address and shipping-address both correspond to the Address class. In order to be able to round trip the data we need to keep track of which element we unmarshalled.
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.*;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Customer {
@XmlElementRefs({
@XmlElementRef(name = "billing-address"),
@XmlElementRef(name = "shipping-address")
})
private JAXBElement<Address> address;
}
While useful JAXBElement can get in the way if you want to use your domain model with something like JPA (which doesn't know what to do with it). In this post I will demonstrate how you can eliminate the need for JAXBElement through the use of an XmlAdapter.
Subscribe to:
Posts (Atom)