public final class ConfigMappers
extends java.lang.Object
Note that this class defines many methods of the form <type> to<type>(String)
which are automatically registered with each Config.Builder
.
ConfigMapper
,
ConfigMapperProvider
Modifier and Type | Method | Description |
---|---|---|
static <T> ConfigMapper<T> |
from(java.lang.Class<T> type,
java.lang.Class<?> builderType) |
Creates new instance of
ConfigMapper that creates new instance of type
using specified builder that will be initialized from appropriate Config node. |
static java.math.BigDecimal |
toBigDecimal(java.lang.String stringValue) |
Maps
stringValue to BigDecimal . |
static java.math.BigInteger |
toBigInteger(java.lang.String stringValue) |
Maps
stringValue to BigInteger . |
static java.lang.Boolean |
toBoolean(java.lang.String stringValue) |
Maps
stringValue to boolean . |
static java.lang.Byte |
toByte(java.lang.String stringValue) |
Maps
stringValue to byte . |
static java.util.Calendar |
toCalendar(java.lang.String stringValue) |
Maps
stringValue to Calendar . |
static java.lang.Character |
toChar(java.lang.String stringValue) |
Maps
stringValue to char . |
static java.nio.charset.Charset |
toCharset(java.lang.String stringValue) |
Maps
stringValue to Charset . |
static java.lang.Class<?> |
toClass(java.lang.String stringValue) |
Maps
stringValue to Class<?> . |
static java.util.Date |
toDate(java.lang.String stringValue) |
Maps
stringValue to Date . |
static java.lang.Double |
toDouble(java.lang.String stringValue) |
Maps
stringValue to double . |
static java.time.Duration |
toDuration(java.lang.String stringValue) |
Maps
stringValue to Duration . |
static java.io.File |
toFile(java.lang.String stringValue) |
Maps
stringValue to File . |
static java.lang.Float |
toFloat(java.lang.String stringValue) |
Maps
stringValue to float . |
static java.util.GregorianCalendar |
toGregorianCalendar(java.lang.String stringValue) |
Maps
stringValue to GregorianCalendar . |
static java.time.Instant |
toInstant(java.lang.String stringValue) |
Maps
stringValue to Instant . |
static java.lang.Integer |
toInt(java.lang.String stringValue) |
Maps
stringValue to int . |
static java.time.LocalDate |
toLocalDate(java.lang.String stringValue) |
Maps
stringValue to LocalDate . |
static java.time.LocalDateTime |
toLocalDateTime(java.lang.String stringValue) |
Maps
stringValue to LocalDateTime . |
static java.time.LocalTime |
toLocalTime(java.lang.String stringValue) |
Maps
stringValue to LocalTime . |
static java.lang.Long |
toLong(java.lang.String stringValue) |
Maps
stringValue to long . |
static java.util.Map<java.lang.String,java.lang.String> |
toMap(Config config) |
Transform all leaf nodes (values) into Map instance.
|
static java.time.OffsetDateTime |
toOffsetDateTime(java.lang.String stringValue) |
Maps
stringValue to OffsetDateTime . |
static java.time.OffsetTime |
toOffsetTime(java.lang.String stringValue) |
Maps
stringValue to OffsetTime . |
static java.nio.file.Path |
toPath(java.lang.String stringValue) |
Maps
stringValue to Path . |
static java.util.regex.Pattern |
toPattern(java.lang.String stringValue) |
Maps
stringValue to Pattern . |
static java.time.Period |
toPeriod(java.lang.String stringValue) |
Maps
stringValue to Period . |
static java.util.Properties |
toProperties(Config config) |
Transform all leaf nodes (values) into Properties instance.
|
static java.lang.Short |
toShort(java.lang.String stringValue) |
Maps
stringValue to short . |
static java.util.SimpleTimeZone |
toSimpleTimeZone(java.lang.String stringValue) |
Maps
stringValue to SimpleTimeZone . |
static java.util.TimeZone |
toTimeZone(java.lang.String stringValue) |
Maps
stringValue to TimeZone . |
static java.net.URI |
toUri(java.lang.String stringValue) |
Maps
stringValue to URI . |
static java.net.URL |
toUrl(java.lang.String stringValue) |
Maps
stringValue to URL . |
static java.util.UUID |
toUUID(java.lang.String stringValue) |
Maps
stringValue to UUID . |
static java.time.ZonedDateTime |
toZonedDateTime(java.lang.String stringValue) |
Maps
stringValue to ZonedDateTime . |
static java.time.ZoneId |
toZoneId(java.lang.String stringValue) |
Maps
stringValue to ZoneId . |
static java.time.ZoneOffset |
toZoneOffset(java.lang.String stringValue) |
Maps
stringValue to ZoneOffset . |
public static java.lang.Byte toByte(java.lang.String stringValue)
stringValue
to byte
.stringValue
- source value as a String
stringValue
to byte
public static java.lang.Short toShort(java.lang.String stringValue)
stringValue
to short
.stringValue
- source value as a String
stringValue
to short
public static java.lang.Integer toInt(java.lang.String stringValue)
stringValue
to int
.stringValue
- source value as a String
stringValue
to int
public static java.lang.Long toLong(java.lang.String stringValue)
stringValue
to long
.stringValue
- source value as a String
stringValue
to long
public static java.lang.Float toFloat(java.lang.String stringValue)
stringValue
to float
.stringValue
- source value as a String
stringValue
to float
public static java.lang.Double toDouble(java.lang.String stringValue)
stringValue
to double
.stringValue
- source value as a String
stringValue
to double
public static java.lang.Boolean toBoolean(java.lang.String stringValue)
stringValue
to boolean
.stringValue
- source value as a String
stringValue
to boolean
public static java.lang.Character toChar(java.lang.String stringValue)
stringValue
to char
.stringValue
- source value as a String
stringValue
to char
public static java.lang.Class<?> toClass(java.lang.String stringValue)
stringValue
to Class<?>
.stringValue
- source value as a String
stringValue
to Class<?>
public static java.util.UUID toUUID(java.lang.String stringValue)
stringValue
to UUID
.stringValue
- source value as a String
stringValue
to UUID
public static java.math.BigDecimal toBigDecimal(java.lang.String stringValue)
stringValue
to BigDecimal
.stringValue
- source value as a String
stringValue
to BigDecimal
public static java.math.BigInteger toBigInteger(java.lang.String stringValue)
stringValue
to BigInteger
.stringValue
- source value as a String
stringValue
to BigInteger
public static java.io.File toFile(java.lang.String stringValue)
stringValue
to File
.stringValue
- source value as a String
stringValue
to File
public static java.nio.file.Path toPath(java.lang.String stringValue)
stringValue
to Path
.stringValue
- source value as a String
stringValue
to Path
public static java.nio.charset.Charset toCharset(java.lang.String stringValue)
stringValue
to Charset
.stringValue
- source value as a String
stringValue
to Charset
public static java.util.regex.Pattern toPattern(java.lang.String stringValue)
stringValue
to Pattern
.stringValue
- source value as a String
stringValue
to Pattern
public static java.net.URI toUri(java.lang.String stringValue)
stringValue
to URI
.stringValue
- source value as a String
stringValue
to URI
public static java.net.URL toUrl(java.lang.String stringValue)
stringValue
to URL
.stringValue
- source value as a String
stringValue
to URL
public static java.util.Date toDate(java.lang.String stringValue)
stringValue
to Date
.stringValue
- source value as a String
stringValue
to Date
DateTimeFormatter.ISO_DATE_TIME
public static java.util.Calendar toCalendar(java.lang.String stringValue)
stringValue
to Calendar
.stringValue
- source value as a String
stringValue
to Calendar
DateTimeFormatter.ISO_DATE_TIME
public static java.util.GregorianCalendar toGregorianCalendar(java.lang.String stringValue)
stringValue
to GregorianCalendar
.stringValue
- source value as a String
stringValue
to GregorianCalendar
DateTimeFormatter.ISO_DATE_TIME
public static java.time.LocalDate toLocalDate(java.lang.String stringValue)
stringValue
to LocalDate
.stringValue
- source value as a String
stringValue
to LocalDate
LocalDate.parse(CharSequence)
public static java.time.LocalTime toLocalTime(java.lang.String stringValue)
stringValue
to LocalTime
.stringValue
- source value as a String
stringValue
to LocalTime
LocalTime.parse(CharSequence)
public static java.time.LocalDateTime toLocalDateTime(java.lang.String stringValue)
stringValue
to LocalDateTime
.stringValue
- source value as a String
stringValue
to LocalDateTime
LocalDateTime.parse(CharSequence)
public static java.time.ZonedDateTime toZonedDateTime(java.lang.String stringValue)
stringValue
to ZonedDateTime
.stringValue
- source value as a String
stringValue
to ZonedDateTime
ZonedDateTime.parse(CharSequence)
public static java.time.ZoneId toZoneId(java.lang.String stringValue)
stringValue
to ZoneId
.stringValue
- source value as a String
stringValue
to ZoneId
ZoneId.of(String)
public static java.time.ZoneOffset toZoneOffset(java.lang.String stringValue)
stringValue
to ZoneOffset
.stringValue
- source value as a String
stringValue
to ZoneOffset
ZoneOffset.of(String)
public static java.util.TimeZone toTimeZone(java.lang.String stringValue)
stringValue
to TimeZone
.stringValue
- source value as a String
stringValue
to TimeZone
ZoneId.of(String)
public static java.util.SimpleTimeZone toSimpleTimeZone(java.lang.String stringValue)
stringValue
to SimpleTimeZone
.stringValue
- source value as a String
stringValue
to SimpleTimeZone
ZoneId.of(String)
public static java.time.Instant toInstant(java.lang.String stringValue)
stringValue
to Instant
.stringValue
- source value as a String
stringValue
to Instant
Instant.parse(CharSequence)
public static java.time.OffsetDateTime toOffsetDateTime(java.lang.String stringValue)
stringValue
to OffsetDateTime
.stringValue
- source value as a String
stringValue
to OffsetDateTime
OffsetDateTime.parse(CharSequence)
public static java.time.OffsetTime toOffsetTime(java.lang.String stringValue)
stringValue
to OffsetTime
.stringValue
- source value as a String
stringValue
to OffsetTime
OffsetTime.parse(CharSequence)
public static java.time.Duration toDuration(java.lang.String stringValue)
stringValue
to Duration
.stringValue
- source value as a String
stringValue
to Duration
Duration.parse(CharSequence)
public static java.time.Period toPeriod(java.lang.String stringValue)
stringValue
to Period
.stringValue
- source value as a String
stringValue
to Period
Period.parse(CharSequence)
public static java.util.Map<java.lang.String,java.lang.String> toMap(Config config)
Fully qualified key of config node is used as a key in returned Map.
Detach
config node before transforming to Map in case you want to cut
current Config node key prefix.
Let's say we work with following configuration:
app: name: Example 1 page-size: 20 logging: app.level = INFO level = WARNINGMap
app1
contains two keys: app.name
, app.page-size
.
Map<String, String> app1 = ConfigMappers.toMap(config.get("app"));
Detaching
app
config node returns new Config instance with "reset" local root.
Map<String, String> app2 = ConfigMappers.toMap(config.get("app").detach());
Map app2
contains two keys without app
prefix: name
, page-size
.config
- config node used to transform into PropertiesConfig.detach()
public static java.util.Properties toProperties(Config config)
Fully qualified key of config node is used as a key in returned Properties.
Detach
config node before transforming to Properties in case you want to cut
current Config node key prefix.
Let's say we work with following configuration:
app: name: Example 1 page-size: 20 logging: app.level = INFO level = WARNINGProperties
app1
contains two keys: app.name
, app.page-size
.
Properties app1 = ConfigMappers.toProperties(config.get("app"));
Detaching
app
config node returns new Config instance with "reset" local root.
Properties app2 = ConfigMappers.toProperties(config.get("app").detach());Properties
app2
contains two keys without app
prefix: name
, page-size
.config
- config node used to transform into PropertiesConfig.detach()
public static <T> ConfigMapper<T> from(java.lang.Class<T> type, java.lang.Class<?> builderType) throws ConfigException
ConfigMapper
that creates new instance of type
using specified builder that will be initialized from appropriate Config node.
Advantage of this approach is that there is no connection from type
to builderType
and builder instance is initialized as an ordinary type from Config.
T
- supported mapping Java type.type
- supported type of created mapper.builderType
- type of builder used to create type
instance.type
instance using builderType
instanceConfigException
- in case builderType
does not follow builder pattern -
there is no public build()
method that builds type
instance.Copyright © 2018 Oracle Corporation. All rights reserved.