blob: a16f507ca3c2dff0b07614483f0f5d6c6c17f6ed [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<title>Converter</title>
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
<link rel="shortcut icon" href="/img/microprofile-favicon.png">
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Converter";
}
}
catch(err) {
}
//-->
var methods = {"i0":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";
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.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>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/eclipse/microprofile/config/spi/ConfigSourceProvider.html" title="interface in org.eclipse.microprofile.config.spi"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li>Next&nbsp;Class</li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/eclipse/microprofile/config/spi/Converter.html" target="_top">Frames</a></li>
<li><a href="Converter.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></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>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&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>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.eclipse.microprofile.config.spi</div>
<h2 title="Interface Converter" class="title">Interface Converter&lt;T&gt;</h2>
</div>
<div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt>All Superinterfaces:</dt>
<dd>java.io.Serializable</dd>
</dl>
<hr>
<br>
<pre>public interface <span class="typeNameLabel">Converter&lt;T&gt;</span>
extends java.io.Serializable</pre>
<div class="block">A mechanism for converting configured values from <code>String</code> to any Java type.
<h2 id="global_converters">Global converters</h2>
<p>
Converters may be global to a <code>Config</code> instance. Global converters are registered either by being
<a href="#discovery">discovered</a> or explicitly <a href="../../../../../org/eclipse/microprofile/config/spi/ConfigBuilder.html#withConverter-java.lang.Class-int-org.eclipse.microprofile.config.spi.Converter-">added to the configuration</a>.
<p>
Global converters are automatically applied to types that match the converter's type.
<h3 id="built_in_converters">Built-in converters</h3>
<p>
Global converters may be <em>built in</em>. Such converters are provided by the implementation. A compliant
implementation must provide build-in converters for <em>at least</em> the following types:
<ul>
<li><code>boolean</code> and <code>Boolean</code>, returning <code>true</code> for at least the following values (case insensitive):
<ul>
<li><code>true</code></li>
<li><code>yes</code></li>
<li><code>y</code></li>
<li><code>on</code></li>
<li><code>1</code></li>
</ul>
<li><code>byte</code> and <code>Byte</code>, accepting (at minimum) all values accepted by the <code>Byte.parseByte(String)</code>
method</li>
<li><code>short</code> and <code>Short</code>, accepting (at minimum) all values accepted by the <code>Byte.parseByte(String)</code>
method</li>
<li><code>int</code>, <code>Integer</code>, and <code>OptionalInt</code> accepting (at minimum) all values accepted by the
<code>Integer.parseInt(String)</code> method</li>
<li><code>long</code>, <code>Long</code>, and <code>OptionalLong</code> accepting (at minimum) all values accepted by the
<code>Long.parseLong(String)</code> method</li>
<li><code>float</code> and <code>Float</code>, accepting (at minimum) all values accepted by the
<code>Float.parseFloat(String)</code> method</li>
<li><code>double</code>, <code>Double</code>, and <code>OptionalDouble</code> accepting (at minimum) all values accepted by the
<code>Double.parseDouble(String)</code> method</li>
<li><code>java.lang.Class</code> based on the result of <code>Class.forName(java.lang.String)</code></li>
<li><code>java.lang.String</code></li>
</ul>
<h3 id="discovery">Global converter discovery</h3>
<p>
Custom global converters may be added to a configuration via the <code>ServiceLoader</code> mechanism, and as
such can be registered by providing a resource named
"<code>META-INF/services/org.eclipse.microprofile.config.spi.Converter</code>" which contains the fully qualified
<code>Converter</code> implementation class name(s) (one per line) as content.
<p>
It is also possible to explicitly register a global converter to a <a href="../../../../../org/eclipse/microprofile/config/spi/ConfigBuilder.html" title="interface in org.eclipse.microprofile.config.spi">configuration builder</a>
using the <a href="../../../../../org/eclipse/microprofile/config/spi/ConfigBuilder.html#withConverters-org.eclipse.microprofile.config.spi.Converter...-"><code>ConfigBuilder.withConverters(Converter[])</code></a> and
<a href="../../../../../org/eclipse/microprofile/config/spi/ConfigBuilder.html#withConverter-java.lang.Class-int-org.eclipse.microprofile.config.spi.Converter-"><code>ConfigBuilder.withConverter(Class, int, Converter)</code></a> methods.
<h3 id="implicit">Implicit converters</h3>
<p>
If no global converter can be found for a given type, the configuration implementation must attempt to derive an
<em>implicit converter</em> if any of the following are true (in order):
<ul>
<li>the target type has a <code>public static T of(String)</code> method</li>
<li>the target type has a <code>public static T valueOf(String)</code> method</li>
<li>the target type has a <code>public static T parse(CharSequence)</code> method</li>
<li>the target type has a public constructor with a single parameter of type <code>String</code></li>
<li>the target type is an array of any type corresponding to either a registered
<a href="#global_converters"><em>global</em></a> converter or a <a href="#built_in_converters"><em>built in</em></a>
or <em>implicit</em> converter</li>
</ul>
<h3 id="priority">Converter priority</h3>
<p>
A converter implementation class can specify a priority by way of the standard <code>javax.annotation.Priority</code>
annotation or by explicitly specifying the priority value to the appropriate
<a href="../../../../../org/eclipse/microprofile/config/spi/ConfigBuilder.html#withConverter-java.lang.Class-int-org.eclipse.microprofile.config.spi.Converter-">builder method</a>.
<p>
If no priority is explicitly assigned, the default priority value of <code>100</code> is assumed.
<p>
If multiple converters are registered for the same type, the one with the highest numerical priority value will be
used.
<p>
All <em>built in</em> Converters have a priority value of <code>1</code>. <em>Implicit</em> converters are only created
when no other converter was found; therefore, they do not have a priority.
<h3 id="empty">Empty values</h3>
For all converters, the empty string <code>""</code> <em>must</em> be considered an empty value. Some converters
<em>may</em> consider other values to be empty as well.
<p>
Implementations <em>may</em> (but are not required to) implement <code>Config.getOptionalValue()</code> using a
<code>Converter</code>. If so, this converter <em>must</em> return <code>Optional.empty()</code> for an empty input.
<h3>Array conversion</h3>
<p>
A conforming implementation must support the automatic creation of an <em>implicit</em> converter for array types.
This converter uses a comma (<code>U+002C ','</code>) as a delimiter. To allow a comma to be embedded within individual
array element values, it may be escaped using a backslash (<code>U+005C '\'</code>) character. Any escaped comma character
will be included as a plain comma within the single element (the backslash is discarded by the converter).
<p>
Empty elements <em>must</em> not be included in the final array. An array which would consist of only empty values
<em>must</em> be considered empty; the array converter <em>must</em> return <code>null</code> in this case.</div>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<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="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code><a href="../../../../../org/eclipse/microprofile/config/spi/Converter.html" title="type parameter in Converter">T</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/eclipse/microprofile/config/spi/Converter.html#convert-java.lang.String-">convert</a></span>(java.lang.String&nbsp;value)</code>
<div class="block">Convert the given string value to a specified type.</div>
</td>
</tr>
</table>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="convert-java.lang.String-">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>convert</h4>
<pre><a href="../../../../../org/eclipse/microprofile/config/spi/Converter.html" title="type parameter in Converter">T</a>&nbsp;convert(java.lang.String&nbsp;value)
throws java.lang.IllegalArgumentException,
java.lang.NullPointerException</pre>
<div class="block">Convert the given string value to a specified type. Callers <em>must not</em> pass in <code>null</code> for
<code>value</code>; doing so may result in a <code>NullPointerException</code> being thrown.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>value</code> - the string representation of a property value (must not be <code>null</code>)</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the converted value, or <code>null</code> if the value is empty</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.lang.IllegalArgumentException</code> - if the value cannot be converted to the specified type</dd>
<dd><code>java.lang.NullPointerException</code> - if the given value was <code>null</code></dd>
</dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.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>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/eclipse/microprofile/config/spi/ConfigSourceProvider.html" title="interface in org.eclipse.microprofile.config.spi"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li>Next&nbsp;Class</li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/eclipse/microprofile/config/spi/Converter.html" target="_top">Frames</a></li>
<li><a href="Converter.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses-noframe.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>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&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>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>