Exlll / ConfigLib

A Minecraft library for saving, loading, updating, and commenting YAML configuration files
MIT License
135 stars 17 forks source link

Annotation for YML Key #5

Closed KorkugunuB closed 6 years ago

KorkugunuB commented 6 years ago

when parsing yml, can the variable be a different name ? for example java:

@Key("test.1")
private String test = "hello";

@Key("test.2")
private Integer test2 = 5;

config:

test:
     1: 'hello'
     2: 5
Exlll commented 6 years ago

Hi,

no, this is not possible, but you could use a map:

If you are using >= Java 9:

Map<Integer, Object> test = Map.of(1, "hello", 2, 5);

<= Java 8

Map<Integer, Object> test = new HashMap<>();

public MyConfig() {
    test.put(1, "hello");
    test.put(2, 2);
}
KorkugunuB commented 6 years ago

Thanks for the reply. It's better to use it like this.