mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 18:48:20 +08:00
feat(json): Finished json version's provider
This commit is contained in:
@@ -22,6 +22,16 @@ public class JSONSection implements ConfigureSection {
|
||||
|
||||
if (entry.getValue() instanceof Map) {
|
||||
this.data.put(key, new JSONSection(source, (Map<?, ?>) entry.getValue()));
|
||||
} else if (entry.getValue() instanceof List) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
for (Object obj : (List<?>) entry.getValue()) {
|
||||
if (obj instanceof Map) {
|
||||
list.add(new JSONSection(source, (Map<?, ?>) obj));
|
||||
} else {
|
||||
list.add(obj);
|
||||
}
|
||||
}
|
||||
this.data.put(key, list);
|
||||
} else {
|
||||
this.data.put(key, entry.getValue());
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ package config;
|
||||
import cc.carm.lib.configuration.demo.tests.ConfigurationTest;
|
||||
import cc.carm.lib.configuration.json.JSONConfigFactory;
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import cc.carm.lib.configuration.source.loader.PathGenerator;
|
||||
import cc.carm.lib.configuration.source.option.StandardOptions;
|
||||
import cc.carm.lib.configuration.value.ConfigValue;
|
||||
import cc.carm.lib.configuration.value.standard.ConfiguredValue;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
@@ -12,11 +15,17 @@ public class JSONConfigTest {
|
||||
|
||||
protected final ConfigurationHolder<?> holder = JSONConfigFactory
|
||||
.from(new File("target"), "config.json")
|
||||
.option(StandardOptions.PATH_SEPARATOR, '-')
|
||||
.resourcePath("example.json")
|
||||
.build();
|
||||
|
||||
@Test
|
||||
public void onTest() {
|
||||
|
||||
ConfigValue<Boolean> EXAMPLE = ConfiguredValue.of(false);
|
||||
EXAMPLE.initialize(this.holder, "example");
|
||||
|
||||
System.out.println("Example: " + EXAMPLE.get());
|
||||
|
||||
ConfigurationTest.testDemo(this.holder);
|
||||
ConfigurationTest.testInner(this.holder);
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"example": "true"
|
||||
}
|
||||
Reference in New Issue
Block a user