Annotation Type Config.DefaultValue
- Enclosing interface:
Config
-
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanWhether 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 valueThe default value to be used when no property is found.- Returns:
- the default value.
-
useOnEmpty
boolean useOnEmptyWhether 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 likeport=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}withPORTunset, 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:
trueif an empty value is to be replaced by the default value.- Since:
- 2.0.0
- Default:
false
-