blob: f82c675f7431aab3a4c81056381597604f35b5e4 [file] [log] [blame]
<!DOCTYPE HTML>
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (11.0.2) on Wed Apr 22 10:19:16 CDT 2020 -->
<title>XmlAdapter (EclipseLink 3.0.0, API Reference)</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2020-04-22">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
<script type="text/javascript" src="../../../../../jquery/jszip/dist/jszip.min.js"></script>
<script type="text/javascript" src="../../../../../jquery/jszip-utils/dist/jszip-utils.min.js"></script>
<!--[if IE]>
<script type="text/javascript" src="../../../../../jquery/jszip-utils/dist/jszip-utils-ie.min.js"></script>
<![endif]-->
<script type="text/javascript" src="../../../../../jquery/jquery-3.3.1.js"></script>
<script type="text/javascript" src="../../../../../jquery/jquery-migrate-3.0.1.js"></script>
<script type="text/javascript" src="../../../../../jquery/jquery-ui.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="XmlAdapter (EclipseLink 3.0.0, API Reference)";
}
}
catch(err) {
}
//-->
var data = {"i0":6,"i1":6};
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],4:["t3","Abstract Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
var pathtoroot = "../../../../../";
var useModuleDirectories = true;
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<header role="banner">
<nav role="navigation">
<div class="fixedNav">
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a id="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a id="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
<div class="aboutLanguage">EclipseLink 3.0.0, API Reference</div>
</div>
<div class="subNav">
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses.html">All&nbsp;Classes</a></li>
</ul>
<ul class="navListSearch">
<li><label for="search">SEARCH:</label>
<input type="text" id="search" value="search" disabled="disabled">
<input type="reset" id="reset" value="reset" disabled="disabled">
</li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a id="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
</div>
<div class="navPadding">&nbsp;</div>
<script type="text/javascript"><!--
$('.navPadding').css('padding-top', $('.fixedNav').css("height"));
//-->
</script>
</nav>
</header>
<!-- ======== START OF CLASS DATA ======== -->
<main role="main">
<div class="header">
<div class="subTitle"><span class="packageLabelInType">Package</span>&nbsp;<a href="package-summary.html">jakarta.xml.bind.annotation.adapters</a></div>
<h2 title="Class XmlAdapter" class="title">Class XmlAdapter&lt;ValueType,&#8203;BoundType&gt;</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">java.lang.Object</a></li>
<li>
<ul class="inheritance">
<li>jakarta.xml.bind.annotation.adapters.XmlAdapter&lt;ValueType,&#8203;BoundType&gt;</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt><span class="paramLabel">Type Parameters:</span></dt>
<dd><code>BoundType</code> - The type that JAXB doesn't know how to handle. An adapter is written
to allow this type to be used as an in-memory representation through
the <code>ValueType</code>.</dd>
<dd><code>ValueType</code> - The type that JAXB knows how to handle out of the box.</dd>
</dl>
<dl>
<dt>Direct Known Subclasses:</dt>
<dd><code><a href="CollapsedStringAdapter.html" title="class in jakarta.xml.bind.annotation.adapters">CollapsedStringAdapter</a></code>, <code><a href="HexBinaryAdapter.html" title="class in jakarta.xml.bind.annotation.adapters">HexBinaryAdapter</a></code>, <code><a href="../../../../../org/eclipse/persistence/jpa/rs/util/xmladapters/LinkAdapter.html" title="class in org.eclipse.persistence.jpa.rs.util.xmladapters">LinkAdapter</a></code>, <code><a href="NormalizedStringAdapter.html" title="class in jakarta.xml.bind.annotation.adapters">NormalizedStringAdapter</a></code>, <code><a href="../../../../../org/eclipse/persistence/jpa/rs/util/xmladapters/ReferenceAdapter.html" title="class in org.eclipse.persistence.jpa.rs.util.xmladapters">ReferenceAdapter</a></code>, <code><a href="../../../../../org/eclipse/persistence/jpa/rs/util/xmladapters/ReferenceAdapterV2.html" title="class in org.eclipse.persistence.jpa.rs.util.xmladapters">ReferenceAdapterV2</a></code>, <code><a href="../../../../../org/eclipse/persistence/jpa/rs/util/xmladapters/RelationshipLinkAdapter.html" title="class in org.eclipse.persistence.jpa.rs.util.xmladapters">RelationshipLinkAdapter</a></code>, <code><a href="../../../../../org/eclipse/persistence/jpa/rs/util/xmladapters/RestCollectionAdapter.html" title="class in org.eclipse.persistence.jpa.rs.util.xmladapters">RestCollectionAdapter</a></code></dd>
</dl>
<hr>
<pre>public abstract class <span class="typeNameLabel">XmlAdapter&lt;ValueType,&#8203;BoundType&gt;</span>
extends <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">Object</a></pre>
<div class="block">Adapts a Java type for custom marshaling.
<p> <b> Usage: </b> </p>
<p>
Some Java types do not map naturally to an XML representation, for
example <code>HashMap</code> or other non JavaBean classes. Conversely,
an XML representation may map to a Java type but an application may
choose to access the XML representation using another Java
type. For example, the schema to Java binding rules bind
xs:DateTime by default to XmlGregorianCalendar. But an application
may desire to bind xs:DateTime to a custom type,
MyXmlGregorianCalendar, for example. In both cases, there is a
mismatch between <i> bound type </i>, used by an application to
access XML content and the <i> value type</i>, that is mapped to an
XML representation.
<p>
This abstract class defines methods for adapting a bound type to a value
type or vice versa. The methods are invoked by the JAXB binding
framework during marshaling and unmarshalling:
<ul>
<li> <b> XmlAdapter.marshal(...): </b> During marshalling, JAXB
binding framework invokes XmlAdapter.marshal(..) to adapt a
bound type to value type, which is then marshaled to XML
representation. </li>
<li> <b> XmlAdapter.unmarshal(...): </b> During unmarshalling,
JAXB binding framework first unmarshals XML representation
to a value type and then invokes XmlAdapter.unmarshal(..) to
adapt the value type to a bound type. </li>
</ul>
Writing an adapter therefore involves the following steps:
<ul>
<li> Write an adapter that implements this abstract class. </li>
<li> Install the adapter using the annotation <a href="XmlJavaTypeAdapter.html" title="annotation in jakarta.xml.bind.annotation.adapters"><code>XmlJavaTypeAdapter</code></a> </li>
</ul>
<p><b>Example:</b> Customized mapping of <code>HashMap</code></p>
<p> The following example illustrates the use of
<code>@XmlAdapter</code> and <code>@XmlJavaTypeAdapter</code> to
customize the mapping of a <code>HashMap</code>.
<p> <b> Step 1: </b> Determine the desired XML representation for HashMap.
<pre><code>
&lt;hashmap&gt;
&lt;entry key="id123"&gt;this is a value&lt;/entry&gt;
&lt;entry key="id312"&gt;this is another value&lt;/entry&gt;
...
&lt;/hashmap&gt;
</code></pre>
<p> <b> Step 2: </b> Determine the schema definition that the
desired XML representation shown above should follow.
<pre><code>
&lt;xs:complexType name="myHashMapType"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="entry" type="myHashMapEntryType"
minOccurs = "0" maxOccurs="unbounded"/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:complexType name="myHashMapEntryType"&gt;
&lt;xs:simpleContent&gt;
&lt;xs:extension base="xs:string"&gt;
&lt;xs:attribute name="key" type="xs:int"/&gt;
&lt;/xs:extension&gt;
&lt;/xs:simpleContent&gt;
&lt;/xs:complexType&gt;
</code></pre>
<p> <b> Step 3: </b> Write value types that can generate the above
schema definition.
<pre>
public class MyHashMapType {
List&lt;MyHashMapEntryType&gt; entry;
}
public class MyHashMapEntryType {
&#64;XmlAttribute
public Integer key;
&#64;XmlValue
public String value;
}
</pre>
<p> <b> Step 4: </b> Write the adapter that adapts the value type,
MyHashMapType to a bound type, HashMap, used by the application.
<pre><code>
public final class MyHashMapAdapter extends
XmlAdapter&lt;MyHashMapType,HashMap&gt; { ... }
</code></pre>
<p> <b> Step 5: </b> Use the adapter.
<pre>
public class Foo {
&#64;XmlJavaTypeAdapter(MyHashMapAdapter.class)
HashMap hashmap;
...
}
</pre>
The above code fragment will map to the following schema:
<pre><code>
&lt;xs:complexType name="Foo"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="hashmap" type="myHashMapType"&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
</code></pre></div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="XmlJavaTypeAdapter.html" title="annotation in jakarta.xml.bind.annotation.adapters"><code>XmlJavaTypeAdapter</code></a></dd>
<dt><span class="simpleTagLabel">Author:</span></dt>
<dd><ul><li>Sekhar Vajjhala, Sun Microsystems Inc.</li> <li> Kohsuke Kawaguchi, Sun Microsystems Inc.</li></ul></dd>
<dt><span class="simpleTagLabel">Since:</span></dt>
<dd>1.6, JAXB 2.0</dd>
</dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="constructor.summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<table class="memberSummary">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier</th>
<th class="colSecond" scope="col">Constructor</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>protected </code></td>
<th class="colConstructorName" scope="row"><code><span class="memberNameLink"><a href="#%3Cinit%3E()">XmlAdapter</a></span>()</code></th>
<td class="colLast">
<div class="block">Do-nothing constructor for the derived classes.</div>
</td>
</tr>
</table>
</li>
</ul>
</section>
<!-- ========== METHOD SUMMARY =========== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t3" class="tableTab"><span><a href="javascript:show(4);">Abstract Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colSecond" scope="col">Method</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>abstract <a href="XmlAdapter.html" title="type parameter in XmlAdapter">ValueType</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#marshal(BoundType)">marshal</a></span>&#8203;(<a href="XmlAdapter.html" title="type parameter in XmlAdapter">BoundType</a>&nbsp;v)</code></th>
<td class="colLast">
<div class="block">Convert a bound type to a value type.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>abstract <a href="XmlAdapter.html" title="type parameter in XmlAdapter">BoundType</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#unmarshal(ValueType)">unmarshal</a></span>&#8203;(<a href="XmlAdapter.html" title="type parameter in XmlAdapter">ValueType</a>&nbsp;v)</code></th>
<td class="colLast">
<div class="block">Convert a value type to a bound type.</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a id="methods.inherited.from.class.java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">Object</a></h3>
<code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang" class="externalLink">clone</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang" class="externalLink">equals</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang" class="externalLink">finalize</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang" class="externalLink">getClass</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang" class="externalLink">hashCode</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang" class="externalLink">notify</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang" class="externalLink">notifyAll</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang" class="externalLink">toString</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang" class="externalLink">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang" class="externalLink">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait(long,int)" title="class or interface in java.lang" class="externalLink">wait</a></code></li>
</ul>
</li>
</ul>
</section>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="constructor.detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a id="&lt;init&gt;()">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>XmlAdapter</h4>
<pre>protected&nbsp;XmlAdapter()</pre>
<div class="block">Do-nothing constructor for the derived classes.</div>
</li>
</ul>
</li>
</ul>
</section>
<!-- ============ METHOD DETAIL ========== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a id="unmarshal(java.lang.Object)">
<!-- -->
</a><a id="unmarshal(ValueType)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>unmarshal</h4>
<pre class="methodSignature">public abstract&nbsp;<a href="XmlAdapter.html" title="type parameter in XmlAdapter">BoundType</a>&nbsp;unmarshal&#8203;(<a href="XmlAdapter.html" title="type parameter in XmlAdapter">ValueType</a>&nbsp;v)
throws <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang" class="externalLink">Exception</a></pre>
<div class="block">Convert a value type to a bound type.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>v</code> - The value to be converted. Can be null.</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang" class="externalLink">Exception</a></code> - if there's an error during the conversion. The caller is responsible for
reporting the error to the user through <a href="../../ValidationEventHandler.html" title="interface in jakarta.xml.bind"><code>ValidationEventHandler</code></a>.</dd>
</dl>
</li>
</ul>
<a id="marshal(java.lang.Object)">
<!-- -->
</a><a id="marshal(BoundType)">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>marshal</h4>
<pre class="methodSignature">public abstract&nbsp;<a href="XmlAdapter.html" title="type parameter in XmlAdapter">ValueType</a>&nbsp;marshal&#8203;(<a href="XmlAdapter.html" title="type parameter in XmlAdapter">BoundType</a>&nbsp;v)
throws <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang" class="externalLink">Exception</a></pre>
<div class="block">Convert a bound type to a value type.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>v</code> - The value to be convereted. Can be null.</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang" class="externalLink">Exception</a></code> - if there's an error during the conversion. The caller is responsible for
reporting the error to the user through <a href="../../ValidationEventHandler.html" title="interface in jakarta.xml.bind"><code>ValidationEventHandler</code></a>.</dd>
</dl>
</li>
</ul>
</li>
</ul>
</section>
</li>
</ul>
</div>
</div>
</main>
<!-- ========= END OF CLASS DATA ========= -->
<footer role="contentinfo">
<nav role="navigation">
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a id="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a id="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
<div class="aboutLanguage">EclipseLink 3.0.0, API Reference</div>
</div>
<div class="subNav">
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a id="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</nav>
<p class="legalCopy"><small>Copyright &#169; 2017&#x2013;2020 <a href="http://www.eclipse.org/eclipselink">Eclipse.org - EclipseLink Project</a>. All rights reserved.</small></p>
</footer>
</body>
</html>