Change property's name

We all secretly love lowercased hyphenated names, I know, I know.

From a single field

To set a custom name on a single field, you can annotate it with @Name and provide the new name, or @NamedPath to specify a path and name at once. Note that this does override any selected Naming scheme.

import com.github.secretx33.sccfg.api.annotation.*;

@Configuration
public class MyConfig {
    
    // annotate the field with @Name, and provide any name you'd like
    @Name("otherNameOnField")
    private final int someInt = 0;
    
    // or use the combo annotation, NamedPath
    @NamedPath(path = "the.path", name = "anotherName")
    public String someString = "edisson";
}

Will generate the following file.

otherNameOnField: 0
the:
  path:
    anotherName: "edisson"

From all fields at once

Choose a different Naming scheme for your configuration fields by modifying your @Configuration annotation. This option will affect all field names, except those which have @Name annotation, which has a tighter scope.

These are the available Naming options.

  • NONE

  • LOWERCASE_HYPHENATED

  • LOWERCASE_UNDERLINED

  • UPPERCASE_HYPHENATED

  • UPPERCASE_UNDERLINED

As for the example, let's randomly pick LOWERCASE_HYPHENATED for demonstration purposes.

import com.github.secretx33.sccfg.api.*;

@Configuration(naming = Naming.LOWERCASE_HYPHENATED)
public class MyConfig {
    
    public int someInt = 0;
    public final String SOME_SCREAMING_VARIABLE = "screaming";
}

Will produce the following output file.

some-int: 0
some-screaming-variable: screaming

Last updated