-
Notifications
You must be signed in to change notification settings - Fork 8
Naming conventions
Ridan Vandenbergh edited this page Mar 22, 2020
·
4 revisions
Note: this information only applies to the annotation system!
You might not want your configuration to use the names of the fields in your POJO. By default, fiber applies a NoNamingConvention
: meaning none of the fields will be renamed when converting a POJO into an IR.
You can adjust this behaviour by choosing another naming convention, or by creating your own. The naming convention is passed in the @Settings
annotation, targeting your POJO class:
@Settings(namingConvention = NoNamingConvention.class)
public class MyConfiguration {
private int fooBar = 5;
}
Available naming conventions are:
Name | Field name | Setting name |
---|---|---|
UnderscoredLowerCaseConvention | fooBar | foo_bar |
LowercaseConvention | fooBar | foobar |
NoNamingConvention | fooBar | fooBar |
Create a class without constructor that implements SettingNamingConvention
. For example, let's create a new naming convention, UppercaseConvention.
public class UppercaseConvention implements SettingNamingConvention {
@Override
public String name(String name) {
// name is the name of the field we will be renaming
return name.toUpperCase(); // we return the upper case version of the field's name
}
}
Afterwards, you can just start using it like any other naming convention:
@Settings(namingConvention = UppercaseConvention.class)
public class MyConfiguration {
private int fooBar = 5; // will become FOOBAR in the configuration
}