Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 332751 - [OXM] xml-java-type-adapter doesn't work with built-in JAXB HexBinaryAdapter
Summary: [OXM] xml-java-type-adapter doesn't work with built-in JAXB HexBinaryAdapter
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: David McCann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-16 10:51 EST by Rick Barkhouse CLA
Modified: 2022-06-09 10:10 EDT (History)
1 user (show)

See Also:


Attachments
Test Case demonstrating bug (2.14 KB, application/zip)
2010-12-16 10:53 EST, Rick Barkhouse CLA
no flags Details
Proposed fix (4.47 KB, patch)
2010-12-22 09:29 EST, David McCann CLA
no flags Details | Diff
Supporting tests (24.98 KB, patch)
2010-12-22 09:30 EST, David McCann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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