Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/MOXy/Simple Values/Special Schema Types/Binary Types"

Line 24: Line 24:
  
 
@XmlRootElement
 
@XmlRootElement
@XmlAccessorType(AccessType.FIELD)
+
public class BinaryData {
public class Employee {
+
  
   private String name;
+
   public byte[] primitiveBytes;
   private byte[] photo;
+
   public Byte[] byteObjects;
  private Byte[] pgpKey;
+
 
  ...
+
}
 +
</source>
 +
 
 +
<div style="width:700px">
 +
<source lang="java">
 +
BinaryData b = new BinaryData();
 +
b.primitiveBytes = new byte[] {34,45,56,67,78,89,89,34,23,12,12,11,2};
 +
b.byteObjects = new Byte[] {23,1,112,12,1,64,1,14,3,2};
 +
 
 +
jaxbContext.createMarshaller().marshal(b, System.out);
 +
</source>
 +
 
 +
 
 +
<div style="width:700px">
 +
<source lang="xml">
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<binaryData>
 +
  <primitiveBytes>Ii04Q05ZWSIXDAwLAg==</primitiveBytes>
 +
  <byteObjects>23</byteObjects>
 +
  <byteObjects>1</byteObjects>
 +
  <byteObjects>112</byteObjects>
 +
  <byteObjects>12</byteObjects>
 +
  <byteObjects>1</byteObjects>
 +
  <byteObjects>64</byteObjects>
 +
  <byteObjects>1</byteObjects>
 +
  <byteObjects>14</byteObjects>
 +
  <byteObjects>3</byteObjects>
 +
  <byteObjects>2</byteObjects>
 +
</binaryData>
 
</source>
 
</source>

Revision as of 15:10, 28 June 2011

EclipseLink MOXy

Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse Source

Elug api package icon.png Key API

Binary Types

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


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.

package example;
 
import javax.xml.bind.annotation.*;
 
@XmlRootElement
public class BinaryData {
 
   public byte[] primitiveBytes;
   public Byte[] byteObjects;
 
}
BinaryData b = new BinaryData();
b.primitiveBytes = new byte[] {34,45,56,67,78,89,89,34,23,12,12,11,2};
b.byteObjects = new Byte[] {23,1,112,12,1,64,1,14,3,2};
 
jaxbContext.createMarshaller().marshal(b, System.out);


<?xml version="1.0" encoding="UTF-8"?>
<binaryData>
   <primitiveBytes>Ii04Q05ZWSIXDAwLAg==</primitiveBytes>
   <byteObjects>23</byteObjects>
   <byteObjects>1</byteObjects>
   <byteObjects>112</byteObjects>
   <byteObjects>12</byteObjects>
   <byteObjects>1</byteObjects>
   <byteObjects>64</byteObjects>
   <byteObjects>1</byteObjects>
   <byteObjects>14</byteObjects>
   <byteObjects>3</byteObjects>
   <byteObjects>2</byteObjects>
</binaryData>

Back to the top