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 and 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 StringstringValue to bytepublic static java.lang.Short toShort(java.lang.String stringValue)
stringValue to short.stringValue - source value as a StringstringValue to shortpublic static java.lang.Integer toInt(java.lang.String stringValue)
stringValue to int.stringValue - source value as a StringstringValue to intpublic static java.lang.Long toLong(java.lang.String stringValue)
stringValue to long.stringValue - source value as a StringstringValue to longpublic static java.lang.Float toFloat(java.lang.String stringValue)
stringValue to float.stringValue - source value as a StringstringValue to floatpublic static java.lang.Double toDouble(java.lang.String stringValue)
stringValue to double.stringValue - source value as a StringstringValue to doublepublic static java.lang.Boolean toBoolean(java.lang.String stringValue)
stringValue to boolean.stringValue - source value as a StringstringValue to booleanpublic static java.lang.Character toChar(java.lang.String stringValue)
stringValue to char.stringValue - source value as a StringstringValue to charpublic static java.lang.Class<?> toClass(java.lang.String stringValue)
stringValue to Class<?>.stringValue - source value as a StringstringValue to Class<?>public static java.util.UUID toUUID(java.lang.String stringValue)
stringValue to UUID.stringValue - source value as a StringstringValue to UUIDpublic static java.math.BigDecimal toBigDecimal(java.lang.String stringValue)
stringValue to BigDecimal.stringValue - source value as a StringstringValue to BigDecimalpublic static java.math.BigInteger toBigInteger(java.lang.String stringValue)
stringValue to BigInteger.stringValue - source value as a StringstringValue to BigIntegerpublic static java.io.File toFile(java.lang.String stringValue)
stringValue to File.stringValue - source value as a StringstringValue to Filepublic static java.nio.file.Path toPath(java.lang.String stringValue)
stringValue to Path.stringValue - source value as a StringstringValue to Pathpublic static java.nio.charset.Charset toCharset(java.lang.String stringValue)
stringValue to Charset.stringValue - source value as a StringstringValue to Charsetpublic static java.util.regex.Pattern toPattern(java.lang.String stringValue)
stringValue to Pattern.stringValue - source value as a StringstringValue to Patternpublic static java.net.URI toUri(java.lang.String stringValue)
stringValue to URI.stringValue - source value as a StringstringValue to URIpublic static java.net.URL toUrl(java.lang.String stringValue)
stringValue to URL.stringValue - source value as a StringstringValue to URLpublic static java.util.Date toDate(java.lang.String stringValue)
stringValue to Date.stringValue - source value as a StringstringValue to DateDateTimeFormatter.ISO_DATE_TIMEpublic static java.util.Calendar toCalendar(java.lang.String stringValue)
stringValue to Calendar.stringValue - source value as a StringstringValue to CalendarDateTimeFormatter.ISO_DATE_TIMEpublic static java.util.GregorianCalendar toGregorianCalendar(java.lang.String stringValue)
stringValue to GregorianCalendar.stringValue - source value as a StringstringValue to GregorianCalendarDateTimeFormatter.ISO_DATE_TIMEpublic static java.time.LocalDate toLocalDate(java.lang.String stringValue)
stringValue to LocalDate.stringValue - source value as a StringstringValue to LocalDateLocalDate.parse(CharSequence)public static java.time.LocalTime toLocalTime(java.lang.String stringValue)
stringValue to LocalTime.stringValue - source value as a StringstringValue to LocalTimeLocalTime.parse(CharSequence)public static java.time.LocalDateTime toLocalDateTime(java.lang.String stringValue)
stringValue to LocalDateTime.stringValue - source value as a StringstringValue to LocalDateTimeLocalDateTime.parse(CharSequence)public static java.time.ZonedDateTime toZonedDateTime(java.lang.String stringValue)
stringValue to ZonedDateTime.stringValue - source value as a StringstringValue to ZonedDateTimeZonedDateTime.parse(CharSequence)public static java.time.ZoneId toZoneId(java.lang.String stringValue)
stringValue to ZoneId.stringValue - source value as a StringstringValue to ZoneIdZoneId.of(String)public static java.time.ZoneOffset toZoneOffset(java.lang.String stringValue)
stringValue to ZoneOffset.stringValue - source value as a StringstringValue to ZoneOffsetZoneOffset.of(String)public static java.util.TimeZone toTimeZone(java.lang.String stringValue)
stringValue to TimeZone.stringValue - source value as a StringstringValue to TimeZoneZoneId.of(String)public static java.util.SimpleTimeZone toSimpleTimeZone(java.lang.String stringValue)
stringValue to SimpleTimeZone.stringValue - source value as a StringstringValue to SimpleTimeZoneZoneId.of(String)public static java.time.Instant toInstant(java.lang.String stringValue)
stringValue to Instant.stringValue - source value as a StringstringValue to InstantInstant.parse(CharSequence)public static java.time.OffsetDateTime toOffsetDateTime(java.lang.String stringValue)
stringValue to OffsetDateTime.stringValue - source value as a StringstringValue to OffsetDateTimeOffsetDateTime.parse(CharSequence)public static java.time.OffsetTime toOffsetTime(java.lang.String stringValue)
stringValue to OffsetTime.stringValue - source value as a StringstringValue to OffsetTimeOffsetTime.parse(CharSequence)public static java.time.Duration toDuration(java.lang.String stringValue)
stringValue to Duration.stringValue - source value as a StringstringValue to DurationDuration.parse(CharSequence)public static java.time.Period toPeriod(java.lang.String stringValue)
stringValue to Period.stringValue - source value as a StringstringValue to PeriodPeriod.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 = WARNING
Map 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 = WARNING
Properties 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 and/or its affiliates. All Rights Reserved. Use is subject to license terms.