Annotation Type Config.DefaultValue

Enclosing interface:
Config

@Retention(RUNTIME) @Target(METHOD) @Documented public static @interface Config.DefaultValue
Default value to be used if no property is found. No quoting (other than normal Java string quoting) is done.
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The default value to be used when no property is found.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Whether a property that is found but empty is to be treated as if it were missing, and the default used in its place.
  • Element Details

    • value

      String value
      The default value to be used when no property is found.
      Returns:
      the default value.
    • useOnEmpty

      boolean useOnEmpty
      Whether a property that is found but empty is to be treated as if it were missing, and the default used in its place.

      A property that is set is normally kept as it is, and the default only covers the case of a property that is not there at all: port= is a value like any other, and an empty value on a type that cannot represent it fails the conversion. That is the same distinction other configuration libraries draw, and it is what keeps a typo like port=8O80, written with the letter O, from silently becoming the default.

      There is a case where the distinction is not useful though, and this is what this flag is for: a value left empty by a template, as in port=${PORT} with PORT unset, carries no information, and falling back on the default is more useful than failing. Since it changes what a property means, it is opt-in and applies to the annotated method only. A value made of whitespace counts as empty, consistently with the rule that already makes it an empty collection.

      The default value goes through preprocessing, variable expansion, decryption and parameter formatting exactly as the value it replaces, so the result is the same as if the property had not been there. Note that the substitution happens on the value returned by the method: Accessible.getProperty(java.lang.String) and the other methods reading the properties directly keep returning the empty value.

      Returns:
      true if an empty value is to be replaced by the default value.
      Since:
      2.0.0
      Default:
      false