Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/MOXy/Mapping the Unmappable/Converters"

Line 11: Line 11:
 
= XmlAdapter =
 
= XmlAdapter =
  
JAXB's '''XmlAdapter''' can be used to map classes that would normally be considered "unmappable" - such as classes that do not have a default no-arg constructor, or classes that do not have a natural XML representation.  In a custom subclass of '''XmlAdapter''', you can define define custom code to convert the unmappable class into something that JAXB can handle.  Then, you can use the '''XmlJavaTypeAdapter''' annotation to indicate that your adapter should be used.
+
JAXB's '''XmlAdapter''' can be used to map classes that would normally be considered "unmappable" - such as classes that do not have a default no-arg constructor, or classes for which an XML representation cannot be automatically determined.  In a custom subclass of '''XmlAdapter''', you can define define custom code to convert the unmappable class into something that JAXB can handle.  Then, you can use the '''XmlJavaTypeAdapter''' annotation to indicate that your adapter should be used when working with the unmappable class.
  
= Example =
+
== Example ==
  
 
Our first example will use the following domain class:
 
Our first example will use the following domain class:

Revision as of 14:49, 6 June 2011

EclipseLink MOXy

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

XmlAdapter

JAXB's XmlAdapter can be used to map classes that would normally be considered "unmappable" - such as classes that do not have a default no-arg constructor, or classes for which an XML representation cannot be automatically determined. In a custom subclass of XmlAdapter, you can define define custom code to convert the unmappable class into something that JAXB can handle. Then, you can use the XmlJavaTypeAdapter annotation to indicate that your adapter should be used when working with the unmappable class.

Example

Our first example will use the following domain class:

package example;
 
import java.util.Currency;
 
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class PurchaseOrder {
 
   private Double amount;
 
   private Currency currency;
 
   ...
}