Name... that... field! String constants for your field's names.
@FieldNameConstants was introduced as experimental feature in lombok v1.16.22.
- New feature; unsure if this busts enough boilerplate.
@FieldNameConstants annotation generates string constants (fields marked
public static final, of type
java.lang.String) containing the field's name, as a string. This is useful for various marshalling and serialization frameworks. The constant field by default is named
FIELD_NAME_OF_FIELD, where NAME_OF_FIELD is the same name as the field it represents, except with all uppercase letters, with underscores in front of the uppercase letters in the original field. The prefix (and suffix) is configurable on the
public access modifier can be changed via the parameter
level = AccessLevel.PACKAGE for example. You can force a field to be skipped by supplying
level = AccessLevel.NONE.
Can be applied to classes (in which case every field gets a constant), or to an individual field.
Supported configuration keys:
error] (default: not set)
Lombok will flag any usage of
@FieldDefaultsas a warning or error if configured.
lombok.fieldNameConstants.prefix= a string (default: 'PREFIX_')
- Lombok will generate the name for each fieldconstant by constant-casing the field name and then prefixing this string to the result.
lombok.fieldNameConstants.suffix= a string (default: '' - the blank string)
- Lombok will generate the name for each fieldconstant by constant-casing the field name and then suffixing this string to the result.
Like other lombok handlers that touch fields, any field whose name starts with a dollar (
$) symbol is skipped entirely. Such a field will not be modified at all. Static fields are also skipped.
The annotation can itself be used to set prefix/suffix. If you do so, it overrides the
lombok.fieldNameConstants.prefix/suffix config key. Example:
@FieldNameConstants(prefix = ""): This would generate for field
helloWorld a constant named
HELLO_WORLD instead of the default