JSON fixes
This commit is contained in:
parent
e1e29be314
commit
ff22f74fdf
2 changed files with 26 additions and 31 deletions
|
@ -35,13 +35,11 @@ public abstract class Config {
|
||||||
String str = configKeeper.getValue(key);
|
String str = configKeeper.getValue(key);
|
||||||
if (str == null) {
|
if (str == null) {
|
||||||
StringEntry entry = this.configKeeper.registerEntry(key, new StringEntry(defaultValue));
|
StringEntry entry = this.configKeeper.registerEntry(key, new StringEntry(defaultValue));
|
||||||
if (settings != null) {
|
|
||||||
if (settings != null) {
|
if (settings != null) {
|
||||||
this.configKeeper.loadFromJson(settings, key, entry);
|
this.configKeeper.loadFromJson(settings, key, entry);
|
||||||
return entry.getValue();
|
return entry.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return str != null ? str : defaultValue;
|
return str != null ? str : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,13 +64,11 @@ public abstract class Config {
|
||||||
Integer val = configKeeper.getValue(key);
|
Integer val = configKeeper.getValue(key);
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
IntegerEntry entry = this.configKeeper.registerEntry(key, new IntegerEntry(defaultValue));
|
IntegerEntry entry = this.configKeeper.registerEntry(key, new IntegerEntry(defaultValue));
|
||||||
if (settings != null) {
|
|
||||||
if (settings != null) {
|
if (settings != null) {
|
||||||
this.configKeeper.loadFromJson(settings, key, entry);
|
this.configKeeper.loadFromJson(settings, key, entry);
|
||||||
return entry.getValue();
|
return entry.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return val != null ? val : defaultValue;
|
return val != null ? val : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,13 +105,11 @@ public abstract class Config {
|
||||||
Float val = configKeeper.getValue(key);
|
Float val = configKeeper.getValue(key);
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
FloatEntry entry = this.configKeeper.registerEntry(key, new FloatEntry(defaultValue));
|
FloatEntry entry = this.configKeeper.registerEntry(key, new FloatEntry(defaultValue));
|
||||||
if (settings != null) {
|
|
||||||
if (settings != null) {
|
if (settings != null) {
|
||||||
this.configKeeper.loadFromJson(settings, key, entry);
|
this.configKeeper.loadFromJson(settings, key, entry);
|
||||||
return entry.getValue();
|
return entry.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return val != null ? val : defaultValue;
|
return val != null ? val : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ public class JsonFactory {
|
||||||
|
|
||||||
public final static Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
public final static Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
|
||||||
|
// Unused
|
||||||
|
@Deprecated
|
||||||
public static JsonObject getJsonObject(String path) throws IOException {
|
public static JsonObject getJsonObject(String path) throws IOException {
|
||||||
try (InputStream is = JsonFactory.class.getResourceAsStream(path)) {
|
try (InputStream is = JsonFactory.class.getResourceAsStream(path)) {
|
||||||
Reader reader = new InputStreamReader(is);
|
Reader reader = new InputStreamReader(is);
|
||||||
|
@ -31,36 +33,38 @@ public class JsonFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unused
|
||||||
|
@Deprecated
|
||||||
public static JsonObject getJsonObject(Resource jsonSource) {
|
public static JsonObject getJsonObject(Resource jsonSource) {
|
||||||
if (jsonSource != null) {
|
if (jsonSource != null) {
|
||||||
try (InputStream is = jsonSource.getInputStream()) {
|
try (InputStream is = jsonSource.getInputStream()) {
|
||||||
Reader reader = new InputStreamReader(is);
|
Reader reader = new InputStreamReader(is);
|
||||||
JsonObject jsonObject = loadJson(reader).getAsJsonObject();
|
JsonElement json = loadJson(reader);
|
||||||
if (jsonObject == null) {
|
if (json != null && json.isJsonObject()) {
|
||||||
return new JsonObject();
|
JsonObject jsonObject = json.getAsJsonObject();
|
||||||
|
return jsonObject != null ? jsonObject : new JsonObject();
|
||||||
}
|
}
|
||||||
return jsonObject;
|
}
|
||||||
} catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
BetterEnd.LOGGER.catching(ex);
|
BetterEnd.LOGGER.catching(ex);
|
||||||
return new JsonObject();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JsonObject();
|
return new JsonObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject getJsonObject(InputStream stream) {
|
public static JsonObject getJsonObject(InputStream stream) {
|
||||||
try {
|
try {
|
||||||
Reader reader = new InputStreamReader(stream);
|
Reader reader = new InputStreamReader(stream);
|
||||||
JsonObject jsonObject = loadJson(reader).getAsJsonObject();
|
JsonElement json = loadJson(reader);
|
||||||
if (jsonObject == null) {
|
if (json != null && json.isJsonObject()) {
|
||||||
return new JsonObject();
|
JsonObject jsonObject = json.getAsJsonObject();
|
||||||
|
return jsonObject != null ? jsonObject : new JsonObject();
|
||||||
}
|
}
|
||||||
return jsonObject;
|
}
|
||||||
} catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
BetterEnd.LOGGER.catching(ex);
|
BetterEnd.LOGGER.catching(ex);
|
||||||
return new JsonObject();
|
|
||||||
}
|
}
|
||||||
|
return new JsonObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject getJsonObject(File jsonFile) {
|
public static JsonObject getJsonObject(File jsonFile) {
|
||||||
|
@ -68,10 +72,7 @@ public class JsonFactory {
|
||||||
JsonElement json = loadJson(jsonFile);
|
JsonElement json = loadJson(jsonFile);
|
||||||
if (json != null && json.isJsonObject()) {
|
if (json != null && json.isJsonObject()) {
|
||||||
JsonObject jsonObject = json.getAsJsonObject();
|
JsonObject jsonObject = json.getAsJsonObject();
|
||||||
if (jsonObject == null) {
|
return jsonObject != null ? jsonObject : new JsonObject();
|
||||||
return new JsonObject();
|
|
||||||
}
|
|
||||||
return jsonObject;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue