public final class ConfigMappers extends 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(Class<T> type,
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 BigDecimal |
toBigDecimal(String stringValue) |
Maps
stringValue to BigDecimal. |
static BigInteger |
toBigInteger(String stringValue) |
Maps
stringValue to BigInteger. |
static Boolean |
toBoolean(String stringValue) |
Maps
stringValue to boolean. |
static Byte |
toByte(String stringValue) |
Maps
stringValue to byte. |
static Calendar |
toCalendar(String stringValue) |
Maps
stringValue to Calendar. |
static Character |
toChar(String stringValue) |
Maps
stringValue to char. |
static Charset |
toCharset(String stringValue) |
Maps
stringValue to Charset. |
static Class<?> |
toClass(String stringValue) |
Maps
stringValue to Class<?>. |
static Date |
toDate(String stringValue) |
Maps
stringValue to Date. |
static Double |
toDouble(String stringValue) |
Maps
stringValue to double. |
static Duration |
toDuration(String stringValue) |
Maps
stringValue to Duration. |
static File |
toFile(String stringValue) |
Maps
stringValue to File. |
static Float |
toFloat(String stringValue) |
Maps
stringValue to float. |
static GregorianCalendar |
toGregorianCalendar(String stringValue) |
Maps
stringValue to GregorianCalendar. |
static Instant |
toInstant(String stringValue) |
Maps
stringValue to Instant. |
static Integer |
toInt(String stringValue) |
Maps
stringValue to int. |
static LocalDate |
toLocalDate(String stringValue) |
Maps
stringValue to LocalDate. |
static LocalDateTime |
toLocalDateTime(String stringValue) |
Maps
stringValue to LocalDateTime. |
static LocalTime |
toLocalTime(String stringValue) |
Maps
stringValue to LocalTime. |
static Long |
toLong(String stringValue) |
Maps
stringValue to long. |
static Map<String,String> |
toMap(Config config) |
Transform all leaf nodes (values) into Map instance.
|
static OffsetDateTime |
toOffsetDateTime(String stringValue) |
Maps
stringValue to OffsetDateTime. |
static OffsetTime |
toOffsetTime(String stringValue) |
Maps
stringValue to OffsetTime. |
static Path |
toPath(String stringValue) |
Maps
stringValue to Path. |
static Pattern |
toPattern(String stringValue) |
Maps
stringValue to Pattern. |
static Period |
toPeriod(String stringValue) |
Maps
stringValue to Period. |
static Properties |
toProperties(Config config) |
Transform all leaf nodes (values) into Properties instance.
|
static Short |
toShort(String stringValue) |
Maps
stringValue to short. |
static SimpleTimeZone |
toSimpleTimeZone(String stringValue) |
Maps
stringValue to SimpleTimeZone. |
static TimeZone |
toTimeZone(String stringValue) |
Maps
stringValue to TimeZone. |
static URI |
toUri(String stringValue) |
Maps
stringValue to URI. |
static URL |
toUrl(String stringValue) |
Maps
stringValue to URL. |
static UUID |
toUUID(String stringValue) |
Maps
stringValue to UUID. |
static ZonedDateTime |
toZonedDateTime(String stringValue) |
Maps
stringValue to ZonedDateTime. |
static ZoneId |
toZoneId(String stringValue) |
Maps
stringValue to ZoneId. |
static ZoneOffset |
toZoneOffset(String stringValue) |
Maps
stringValue to ZoneOffset. |
public static Byte toByte(String stringValue)
stringValue to byte.stringValue - source value as a StringstringValue to bytepublic static Short toShort(String stringValue)
stringValue to short.stringValue - source value as a StringstringValue to shortpublic static Integer toInt(String stringValue)
stringValue to int.stringValue - source value as a StringstringValue to intpublic static Long toLong(String stringValue)
stringValue to long.stringValue - source value as a StringstringValue to longpublic static Float toFloat(String stringValue)
stringValue to float.stringValue - source value as a StringstringValue to floatpublic static Double toDouble(String stringValue)
stringValue to double.stringValue - source value as a StringstringValue to doublepublic static Boolean toBoolean(String stringValue)
stringValue to boolean.stringValue - source value as a StringstringValue to booleanpublic static Character toChar(String stringValue)
stringValue to char.stringValue - source value as a StringstringValue to charpublic static Class<?> toClass(String stringValue)
stringValue to Class<?>.stringValue - source value as a StringstringValue to Class<?>public static UUID toUUID(String stringValue)
stringValue to UUID.stringValue - source value as a StringstringValue to UUIDpublic static BigDecimal toBigDecimal(String stringValue)
stringValue to BigDecimal.stringValue - source value as a StringstringValue to BigDecimalpublic static BigInteger toBigInteger(String stringValue)
stringValue to BigInteger.stringValue - source value as a StringstringValue to BigIntegerpublic static File toFile(String stringValue)
stringValue to File.stringValue - source value as a StringstringValue to Filepublic static Path toPath(String stringValue)
stringValue to Path.stringValue - source value as a StringstringValue to Pathpublic static Charset toCharset(String stringValue)
stringValue to Charset.stringValue - source value as a StringstringValue to Charsetpublic static Pattern toPattern(String stringValue)
stringValue to Pattern.stringValue - source value as a StringstringValue to Patternpublic static URI toUri(String stringValue)
stringValue to URI.stringValue - source value as a StringstringValue to URIpublic static URL toUrl(String stringValue)
stringValue to URL.stringValue - source value as a StringstringValue to URLpublic static Date toDate(String stringValue)
stringValue to Date.stringValue - source value as a StringstringValue to DateDateTimeFormatter.ISO_DATE_TIMEpublic static Calendar toCalendar(String stringValue)
stringValue to Calendar.stringValue - source value as a StringstringValue to CalendarDateTimeFormatter.ISO_DATE_TIMEpublic static GregorianCalendar toGregorianCalendar(String stringValue)
stringValue to GregorianCalendar.stringValue - source value as a StringstringValue to GregorianCalendarDateTimeFormatter.ISO_DATE_TIMEpublic static LocalDate toLocalDate(String stringValue)
stringValue to LocalDate.stringValue - source value as a StringstringValue to LocalDateLocalDate.parse(CharSequence)public static LocalTime toLocalTime(String stringValue)
stringValue to LocalTime.stringValue - source value as a StringstringValue to LocalTimeLocalTime.parse(CharSequence)public static LocalDateTime toLocalDateTime(String stringValue)
stringValue to LocalDateTime.stringValue - source value as a StringstringValue to LocalDateTimeLocalDateTime.parse(CharSequence)public static ZonedDateTime toZonedDateTime(String stringValue)
stringValue to ZonedDateTime.stringValue - source value as a StringstringValue to ZonedDateTimeZonedDateTime.parse(CharSequence)public static ZoneId toZoneId(String stringValue)
stringValue to ZoneId.stringValue - source value as a StringstringValue to ZoneIdZoneId.of(String)public static ZoneOffset toZoneOffset(String stringValue)
stringValue to ZoneOffset.stringValue - source value as a StringstringValue to ZoneOffsetZoneOffset.of(String)public static TimeZone toTimeZone(String stringValue)
stringValue to TimeZone.stringValue - source value as a StringstringValue to TimeZoneZoneId.of(String)public static SimpleTimeZone toSimpleTimeZone(String stringValue)
stringValue to SimpleTimeZone.stringValue - source value as a StringstringValue to SimpleTimeZoneZoneId.of(String)public static Instant toInstant(String stringValue)
stringValue to Instant.stringValue - source value as a StringstringValue to InstantInstant.parse(CharSequence)public static OffsetDateTime toOffsetDateTime(String stringValue)
stringValue to OffsetDateTime.stringValue - source value as a StringstringValue to OffsetDateTimeOffsetDateTime.parse(CharSequence)public static OffsetTime toOffsetTime(String stringValue)
stringValue to OffsetTime.stringValue - source value as a StringstringValue to OffsetTimeOffsetTime.parse(CharSequence)public static Duration toDuration(String stringValue)
stringValue to Duration.stringValue - source value as a StringstringValue to DurationDuration.parse(CharSequence)public static Period toPeriod(String stringValue)
stringValue to Period.stringValue - source value as a StringstringValue to PeriodPeriod.parse(CharSequence)public static Map<String,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 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(Class<T> type, 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.