Class ConfigMappers

java.lang.Object
io.helidon.config.ConfigMappers

public final class ConfigMappers extends Object
Utility methods for converting configuration to Java types.

Note that this class defines many methods of the form <type> to<type>(String) which are automatically registered with each Config.Builder.

See Also:
  • Method Details

    • toByte

      public static Byte toByte(String stringValue)
      Maps stringValue to byte.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to byte
    • toShort

      public static Short toShort(String stringValue)
      Maps stringValue to short.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to short
    • toInt

      public static Integer toInt(String stringValue)
      Maps stringValue to int.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to int
    • toLong

      public static Long toLong(String stringValue)
      Maps stringValue to long.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to long
    • toFloat

      public static Float toFloat(String stringValue)
      Maps stringValue to float.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to float
    • toDouble

      public static Double toDouble(String stringValue)
      Maps stringValue to double.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to double
    • toBoolean

      public static Boolean toBoolean(String stringValue)
      Maps stringValue to boolean.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to boolean
    • toChar

      public static Character toChar(String stringValue)
      Maps stringValue to char.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to char
    • toClass

      public static Class<?> toClass(String stringValue)
      Maps stringValue to Class<?>.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to Class<?>
    • toUUID

      public static UUID toUUID(String stringValue)
      Maps stringValue to UUID.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to UUID
    • toBigDecimal

      public static BigDecimal toBigDecimal(String stringValue)
      Maps stringValue to BigDecimal.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to BigDecimal
    • toBigInteger

      public static BigInteger toBigInteger(String stringValue)
      Maps stringValue to BigInteger.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to BigInteger
    • toFile

      public static File toFile(String stringValue)
      Maps stringValue to File.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to File
    • toPath

      public static Path toPath(String stringValue)
      Maps stringValue to Path.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to Path
    • toCharset

      public static Charset toCharset(String stringValue)
      Maps stringValue to Charset.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to Charset
    • toPattern

      public static Pattern toPattern(String stringValue)
      Maps stringValue to Pattern.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to Pattern
    • toUri

      public static URI toUri(String stringValue)
      Maps stringValue to URI.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to URI
    • toUrl

      public static URL toUrl(String stringValue)
      Maps stringValue to URL.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to URL
    • toDate

      @Deprecated public static Date toDate(String stringValue)
      Deprecated.
      Use one of the time API classes, such as Instant or ZonedDateTime
      Maps stringValue to Date.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to Date
      See Also:
    • toCalendar

      @Deprecated public static Calendar toCalendar(String stringValue)
      Deprecated.
      use new time API, such as ZonedDateTime
      Maps stringValue to Calendar.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to Calendar
      See Also:
    • toGregorianCalendar

      @Deprecated public static GregorianCalendar toGregorianCalendar(String stringValue)
      Deprecated.
      use new time API, such as ZonedDateTime
      Maps stringValue to GregorianCalendar.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to GregorianCalendar
      See Also:
    • toLocalDate

      public static LocalDate toLocalDate(String stringValue)
      Maps stringValue to LocalDate.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to LocalDate
      See Also:
    • toLocalTime

      public static LocalTime toLocalTime(String stringValue)
      Maps stringValue to LocalTime.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to LocalTime
      See Also:
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(String stringValue)
      Maps stringValue to LocalDateTime.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to LocalDateTime
      See Also:
    • toZonedDateTime

      public static ZonedDateTime toZonedDateTime(String stringValue)
      Maps stringValue to ZonedDateTime.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to ZonedDateTime
      See Also:
    • toZoneId

      public static ZoneId toZoneId(String stringValue)
      Maps stringValue to ZoneId.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to ZoneId
      See Also:
    • toZoneOffset

      public static ZoneOffset toZoneOffset(String stringValue)
      Maps stringValue to ZoneOffset.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to ZoneOffset
      See Also:
    • toTimeZone

      @Deprecated public static TimeZone toTimeZone(String stringValue)
      Deprecated.
      use new time API, such as ZoneId
      Maps stringValue to TimeZone.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to TimeZone
      See Also:
    • toSimpleTimeZone

      @Deprecated public static SimpleTimeZone toSimpleTimeZone(String stringValue)
      Deprecated.
      use new time API, such as ZoneId
      Maps stringValue to SimpleTimeZone.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to SimpleTimeZone
      See Also:
    • toInstant

      public static Instant toInstant(String stringValue)
      Maps stringValue to Instant.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to Instant
      See Also:
    • toOffsetDateTime

      public static OffsetDateTime toOffsetDateTime(String stringValue)
      Maps stringValue to OffsetDateTime.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to OffsetDateTime
      See Also:
    • toOffsetTime

      public static OffsetTime toOffsetTime(String stringValue)
      Maps stringValue to OffsetTime.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to OffsetTime
      See Also:
    • toDuration

      public static Duration toDuration(String stringValue)
      Maps stringValue to Duration.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to Duration
      See Also:
    • toPeriod

      public static Period toPeriod(String stringValue)
      Maps stringValue to Period.
      Parameters:
      stringValue - source value as a String
      Returns:
      mapped stringValue to Period
      See Also:
    • toMap

      public static Map<String,String> toMap(Config config)
      Transform all leaf nodes (values) into Map instance.

      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.
      Parameters:
      config - config node used to transform into Properties
      Returns:
      new Map instance that contains all config leaf node values
      See Also:
    • toProperties

      public static Properties toProperties(Config config)
      Transform all leaf nodes (values) into Properties instance.

      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.
      Parameters:
      config - config node used to transform into Properties
      Returns:
      Properties instance that contains all config leaf node values.
      See Also: