This post will cover how to use an alternate DOM representation (i.e. String) with @XmlAnyElement.
April 15, 2011
@XmlAnyElement and non-DOM Properties
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.
XML Schema to Java - XSD Choice
In a previous blog post I wrote about how to map to the choice structure in XML schema when starting from classes. An astute reader tried generating an object model from that schema and noticed that the JAXB implementation generated something different than expected. In this post I'll explain the difference.
April 12, 2011
JAXB and JSON via Jettison
JAXB implementations (Metro, EclipseLink MOXy, Apache JaxMe, etc) provide an easy means of converting objects to/from XML. There is a library called Jettison that exposes access to JSON messages via the StAX API that a JAXB implementation can use to convert objects to/from JSON. This library is being leveraged by a number of JAX-RS implementations. In this post I'll demonstrate its use in a standalone example.
April 11, 2011
MOXy's XML Metadata in a JAX-RS Service
In previous posts I introduced how EclipseLink JAXB (MOXy) can represent it's metadata as XML, and how MOXy can be used in a JAX-RS service. In this post I'll demonstrate how to leverage MOXy's metadata file in a JAX-RS service by using a ContextResolver.
Labels:
EclipseLink,
Extension,
JAX-RS,
Mapping File,
MOXy,
REST
March 23, 2011
JAXB, Web Services, and Binary Data
When an instance of a class is used with a Web Service, the JAX-WS implementation can choose to handle fields/properties that hold binary data as SOAP attachment. An attachment is a means to send the data outside of the XML message, this is done as an optimization since binary data encoded as a xs:base64Binary string could be quite large. JAXB offers a couple of annotations to control this behaviour:
- @XmlInlineBinaryData
This specifies that the binary data for this field/property must be written to the XML document as xs:base64Binary and not sent as an attachment.
- @XmlMimeType
For properties of type java.awt.Image or javax.xml.transform.Source, this annotation allows the mime type to be specified that will be used for encoding the data as bytes.
Labels:
Attachment,
JAX-WS,
JAXB,
XmlInlineBinaryData,
XmlMimeType
March 22, 2011
Map to Element based on an Attribute Value with EclipseLink JAXB (MOXy)
I am happy to announce that we are expanding MOXy's XPath based mapping in EclipseLink 2.3. You are now able to map to an element based on the value of an attribute. This is done by leveraging XPath predicates via MOXy's @XmlPath annotation.
You can try this out today by downloading one EclipseLink 2.3.0 nightly downloads starting on March 22, 2011 from:
Labels:
EclipseLink,
EclipseLink 2.3,
Extension,
MOXy,
Predicate,
XmlPath
March 11, 2011
Preventing Entity Expansion Attacks in JAXB
This post will cover how to protect yourself from the entity expansion attack when you are using JAXB.
March 9, 2011
Handling Duplicate @XmlRootElement Declarations
The following post was inspired by an answer I gave to a question on Stack Overflow (feel free to up vote). The problem arose from a JAXBContext being created on classes derived from two schemas that both use the same root element. The solution is to supply type of object to the unmarshal operation.
March 8, 2011
Using JAXB to Implement a Copy Operation
The following post was inspired by an answer I gave to a question on Stack Overflow (feel free to up vote). I am not suggesting that JAXB should be used to implement copy methods, instead I'm using a copy operation to demonstrate that JAXB can treat an object model as XML input.
Subscribe to:
Posts (Atom)