Skip to content

Platform-Config을 기반으로 Class안에 있는 변수를 쉽게 저장하기 위해 제작된 라이브러리 입니다.

Notifications You must be signed in to change notification settings

minseonjae/Field-Config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Field-Config

snakeyaml gson lombok

platform-config

Class안에 있는 모든 변수를 Config에 저장합니다.

예제

Test.java

package example.field;

import kr.codingtree.fieldconfig.annotation.ConfigExclude;
import kr.codingtree.fieldconfig.annotation.ConfigName;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test {

    public static int a = 1;

    @ConfigExclude
    public static int b = 1;

    public static String c = "a";

    @ConfigName("리스트")
    public static List<String> list = Arrays.asList("a", "b", "c");

    @ConfigName("맵1")
    public static Map<String, String> map1 = new HashMap();

    @ConfigName("맵2")
    @ConfigExclude
    public static Map<String, String> map2 = new HashMap();
    
}

예제 (yaml config)

FieldYamlConfigTest.java

package example.field;

import kr.codingtree.fieldconfig.FieldConfig;
import kr.codingtree.platformconfig.YamlConfig;

public class FieldYamlConfigTest {

    public static void main(String[] args) {
        Test.map1.put("a", "aa");
        Test.map1.put("b", "bb");
        Test.map1.put("c", "cc");
        Test.map1.put("d", "dd");

        FieldConfig fieldConfig = new FieldConfig("src/main/java/example/field/config.yml", Test.class, YamlConfig.class);

        fieldConfig.load();

        System.out.println("========json");
        System.out.println("a : " + Test.a);
        System.out.println("b : " + Test.b);
        System.out.println("c : " + Test.c);
        System.out.println("list : " + Test.list);
        System.out.println("map1 : " + Test.map1);
        System.out.println("map2 : " + Test.map2);
        System.out.println("맵1 : " + fieldConfig.config.getMap("맵1"));
    }
}

결과 콘솔

========yaml
a : 1
b : 1
c : a
list : [a, b, c]
map1 : {a=aa, b=bb, c=cc, d=dd}
map2 : {}
맵1 : {a=aa, b=bb, c=cc, d=dd}

저장된 config.yml

a: 1
c: a
리스트:
- a
- b
- c
맵1:
  a: aa
  b: bb
  c: cc
  d: dd

예제 (json config)

FieldYamlConfigTest.java

package example.field;

import kr.codingtree.fieldconfig.FieldConfig;
import kr.codingtree.platformconfig.JsonConfig;

public class FieldJsonConfigTest {

    public static void main(String[] args) {
        Test.map1.put("a", "aa");
        Test.map1.put("b", "bb");
        Test.map1.put("c", "cc");
        Test.map1.put("d", "dd");

        FieldConfig fieldConfig = new FieldConfig("src/main/java/example/field/config.json", Test.class, JsonConfig.class);

        fieldConfig.load();

        System.out.println("========json");
        System.out.println("a : " + Test.a);
        System.out.println("b : " + Test.b);
        System.out.println("c : " + Test.c);
        System.out.println("list : " + Test.list);
        System.out.println("map1 : " + Test.map1);
        System.out.println("map2 : " + Test.map2);
        System.out.println("맵1 : " + fieldConfig.config.getMap("맵1"));
    }

}

결과 콘솔

========json
a : 1
b : 1
c : a
list : [a, b, c]
map1 : {a=aa, b=bb, c=cc, d=dd}
map2 : {}
맵1 : {a=aa, b=bb, c=cc, d=dd}

저장된 config.json

{
  "a": 1.0,
  "c": "a",
  "리스트": [
    "a",
    "b",
    "c"
  ],
  "맵1": {
    "a": "aa",
    "b": "bb",
    "c": "cc",
    "d": "dd"
  }
}

About

Platform-Config을 기반으로 Class안에 있는 변수를 쉽게 저장하기 위해 제작된 라이브러리 입니다.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages