Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 332751

Summary: [OXM] xml-java-type-adapter doesn't work with built-in JAXB HexBinaryAdapter
Product: z_Archived Reporter: Rick Barkhouse <rick.barkhouse>
Component: EclipselinkAssignee: David McCann <david.mccann>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: david.mccann
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Test Case demonstrating bug
none
Proposed fix
none
Supporting tests none

Description Rick Barkhouse CLA 2010-12-16 10:51:34 EST
The JAXB standard way to marshal a byte[] to a hexBinary representation is to use javax.xml.bind.annotation.adapters.HexBinaryAdapter as a Java type adapter.  In annotations this looks like:

@XmlRootElement
public class Customer {
   @XmlElement
   @XmlSchemaType(name="hexBinary")
   @XmlJavaTypeAdapter(HexBinaryAdapter.class)
   public byte[] hexBytes;
   @XmlElement
   public byte[] base64Bytes;
}

This works fine in EclipseLink, but using the equivalent OXM does not:

...
<java-type name="CustomerB">
   <xml-root-element name="customer"/>
   <java-attributes>
      <xml-element java-attribute="picture" xml-inline-binary-data="true">
         <xml-schema-type name="hexBinary"/>
         <xml-java-type-adapter value="javax.xml.bind.annotation.adapters.HexBinaryAdapter"/>
      </xml-element>
      <xml-element java-attribute="resume"/>
   </java-attributes>
</java-type>
...

When marshalled, the <hexBinary> element contains empty string.

This seems to stem from the fact that we go through a different code path if our adapter is not an instance of org.eclipse.persistence.oxm.mappings.converters.XMLConverter.
Comment 1 Rick Barkhouse CLA 2010-12-16 10:53:36 EST
Created attachment 185333 [details]
Test Case demonstrating bug
Comment 2 David McCann CLA 2010-12-22 09:29:51 EST
Created attachment 185706 [details]
Proposed fix
Comment 3 David McCann CLA 2010-12-22 09:30:05 EST
Created attachment 185707 [details]
Supporting tests
Comment 4 David McCann CLA 2010-12-22 10:55:06 EST
Reviewed by:  matt.macivor@oracle.com
Tests:  all unit tests pass as expected; 
jaxb/externalizedmetadata/xmladapter/XmlAdapterTestCases;
jaxb/xmladapter/hexbinary/XmlAdapterHexBinaryTestCases
Revision: 8744
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:10:01 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink