public interface Converter<T> extends Serializable
A mechanism for converting configured values from String
to any Java type.
Config
instance. Global converters are registered
either by being discovered or explicitly
added to the configuration.
Global converters are automatically applied to types that match the converter's type.
boolean
and Boolean
, returning true
for at least the following values (case insensitive):
true
yes
y
on
1
int
and Integer
, accepting (at minimum) all values accepted by the Integer.parseInt(String)
methodlong
and Long
, accepting (at minimum) all values accepted by the Long.parseLong(String)
methodfloat
and Float
, accepting (at minimum) all values accepted by the Float.parseFloat(String)
methoddouble
and Double
, accepting (at minimum) all values accepted by the Double.parseDouble(String)
methodjava.lang.Class
based on the result of Class.forName(java.lang.String)
java.lang.String
ServiceLoader
mechanism, and as such can be
registered by providing a resource named
"META-INF/services/org.eclipse.microprofile.config.spi.Converter
" which contains the fully qualified
Converter
implementation class name(s) (one per line) as content.
It is also possible to explicitly register a global converter to a configuration builder
using the ConfigBuilder.withConverters(Converter[])
and ConfigBuilder.withConverter(Class, int, Converter)
methods.
public static T of(String)
methodpublic static T valueOf(String)
methodpublic static T parse(CharSequence)
methodString
javax.annotation.Priority
annotation
or by explicitly specifying the priority value to the appropriate
builder method.
If no priority is explicitly assigned, the default priority value of 100
is assumed.
If multiple converters are registered for the same type, the one with the highest numerical priority value will be used.
All built in Converters have a priority value of 1
.
Implicit converters are only created when no other converter was found; therefore, they do not have a
priority.
U+002C ','
) as a delimiter. To allow a comma to be embedded within individual
array element values, it may be escaped using a backslash (U+005C '\'
) character. Any escaped comma character
will be included as a plain comma within the single element (the backslash is discarded by the converter).Modifier and Type | Method and Description |
---|---|
T |
convert(String value)
Convert the given string value to a specified type.
|
T convert(String value)
value
- the string representation of a property valuenull
if the value is emptyIllegalArgumentException
- if the value cannot be converted to the specified typeCopyright © 2020 Eclipse Foundation. All rights reserved.