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.

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:

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.