Contents

Binary Types

There are a few extra things to consider when mapping to fields of type byte[] or Byte[].

Binary Formats - Base64 and Hex

EclipseLink supports marshalling and unmarshalling binary data in two different representation formats: base64Binary (default) and hexBinary. You can specify the desired binary format using the @XmlSchemaType annotation, or <xml-schema-type> element in EclipseLink OXM. The example below shows the result of marshalling the same byte[] to each of these formats.

byte[] versus Byte[]

Unlike other Java primitive/wrapper types, Eclipselink differentiates between byte[] (primitive) and Byte[] (wrapper) data types. By default, byte[] will marshal to an element or attribute of type base64Binary, whereas Byte[] will marshal each byte as its own element, as illustrated by the following example:

Working with SOAP Attachments

If you are using EclipseLink MOXy in a Web Services environment, certain types of binary data may be created as an MTOM/XOP Attachment, instead of written directly into an XML element or attribute. This is done as an optimization for large amounts of binary data.

The following table shows the Java types that are automatically treated as Attachments, along with their corresponding MIME type:

MIME Type

Java Type

image/gif

java.awt.Image

image/jpeg

java.awt.Image

text/xmlapplication/xml

javax.xml.transform.Source

*/*

javax.activation.DataHandler

For more information on the basics of SOAP Attachments, see "Appendix H: Enhanced Binary Data Handling" of the Java Architecture for XML Binding (JAXB) 2.2 Specification.