config service: handle fromJson() returning null
Treat it the same as handling a json syntax exception
This commit is contained in:
@@ -233,8 +233,11 @@ public class ConfigService
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
jsonValue = RuneLiteAPI.GSON.fromJson(value, Object.class);
|
jsonValue = RuneLiteAPI.GSON.fromJson(value, Object.class);
|
||||||
|
if (jsonValue == null)
|
||||||
if (jsonValue instanceof Double || jsonValue instanceof Float)
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
else if (jsonValue instanceof Double || jsonValue instanceof Float)
|
||||||
{
|
{
|
||||||
Number number = (Number) jsonValue;
|
Number number = (Number) jsonValue;
|
||||||
if (Math.floor(number.doubleValue()) == number.doubleValue() && !Double.isInfinite(number.doubleValue()))
|
if (Math.floor(number.doubleValue()) == number.doubleValue() && !Double.isInfinite(number.doubleValue()))
|
||||||
@@ -272,6 +275,10 @@ public class ConfigService
|
|||||||
{
|
{
|
||||||
// I couldn't figure out a better way to do this than a second json parse
|
// I couldn't figure out a better way to do this than a second json parse
|
||||||
JsonElement jsonElement = RuneLiteAPI.GSON.fromJson(value, JsonElement.class);
|
JsonElement jsonElement = RuneLiteAPI.GSON.fromJson(value, JsonElement.class);
|
||||||
|
if (jsonElement == null)
|
||||||
|
{
|
||||||
|
return value.length() < MAX_VALUE_LENGTH;
|
||||||
|
}
|
||||||
return validateObject(jsonElement, 1);
|
return validateObject(jsonElement, 1);
|
||||||
}
|
}
|
||||||
catch (JsonSyntaxException ex)
|
catch (JsonSyntaxException ex)
|
||||||
|
|||||||
@@ -51,5 +51,6 @@ public class ConfigServiceTest
|
|||||||
assertTrue(ConfigService.validateJson("\"test\""));
|
assertTrue(ConfigService.validateJson("\"test\""));
|
||||||
assertTrue(ConfigService.validateJson("key:value"));
|
assertTrue(ConfigService.validateJson("key:value"));
|
||||||
assertTrue(ConfigService.validateJson("{\"key\": \"value\"}"));
|
assertTrue(ConfigService.validateJson("{\"key\": \"value\"}"));
|
||||||
|
assertTrue(ConfigService.validateJson("\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user