In previous posts I have demonstrated how powerful JAXB's XmlAdapter can be when starting from domain objects. In this example I will demonstrate how to leverage an XmlAdapter when generating an object model from an XML schema. This post was inspired by an answer I gave to a question on Stack Overflow (feel free to up vote).
August 25, 2011
XML Schema to Java - Generating XmlAdapters
August 24, 2011
JAXB and Enums
Today I answered a question on Stack Overflow (feel free to up vote) about JAXB and generating Java enums from an XML Schema. This is normally straight forward, but there are a couple "gotchas" to be aware of. In this post I'll demonstrate an easy and a harder use case.
Labels:
Bindings File,
Enum,
JAXB,
XmlEnum,
XmlEnumValue
August 23, 2011
JAXB and Java IO (Files, Streams, Readers, and Writers)
JAXB supports many different XML sources and targets. In this post I'll give an overview of how JAXB can be used with those found in the java.io package: File, InputStream, OutputStream, Reader, Writer and their subclasses.
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:
Labels:
EclipseLink,
EclipseLink 2.4,
Extension,
Geocode,
JAXB,
JSON,
MOXy,
XmlPath
August 16, 2011
Using an Unmarshaller.Listener to Capture the Location
Recently I came across a question on Stack Overflow asking how find where in the document an object was unmarshalled from. In this post I'll expand on my answer of using an XMLStreamReader and Unmarshaller.Listener to accomplish this.
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:
You can try this out now using a download available from:
Labels:
EclipseLink,
EclipseLink 2.4,
Extension,
JSON,
MOXy,
Twitter,
XmlAdapter
July 29, 2011
JAXB (XJC) and Nested Classes
Recently I came across a complaint on Twitter about how JAXB (XJC) generates deeply nested class structures from XML schemas. In this post I want to first explain why JAXB does this, and second how to easily configure JAXB not to do this.
June 30, 2011
JAXB and Complex Types with Simple Content
A common question that appears on the forums is something like: "How do I map an object to an XML element with attributes and text in JAXB?". The answer is to use JAXB's @XmlValue annotation. In this post I'll demonstrate how this annotation can be leveraged.
Related Stack Overflow Questions:
Related Stack Overflow Questions:
- How can I add an attribute to a text element in JAXB?
- How to parse <foo value1=“a” value2=“b”>value3</foo> with JAXB?
- XML element with attribute and content using JAXB
June 27, 2011
JAXB and Factory Methods
Everyone knows that by default JAXB uses the no-argument constructor when instantiating objects. Readers of this blog are also familiar with using XmlAdapters to build objects. In this post I'll cover how the use of factory classes and methods can be configured through the @XmlType annotation.
June 24, 2011
Using JAXB's @XmlAccessorType to Configure Field or Property Access
JAXB offers a lot of flexibility when interacting with your object model. One area is configuring the use of fields or properties to access the data in your domain objects. This is specified as an XmlAccessType (PUBLIC_MEMBER, PROPERTY, FIELD, or NONE) via the @XmlAccessorType annotation. In this post we'll examine what these options really mean.
Subscribe to:
Posts (Atom)