Differentiate between int / double in json values
This commit is contained in:
parent
99a2c93ccc
commit
9a943070a9
1 changed files with 12 additions and 4 deletions
|
|
@ -83,10 +83,18 @@ public class JsonConfig implements ServerUtilsConfig {
|
||||||
if (jsonElement == null) return null;
|
if (jsonElement == null) return null;
|
||||||
if (jsonElement.isJsonPrimitive()) {
|
if (jsonElement.isJsonPrimitive()) {
|
||||||
JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonElement;
|
JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonElement;
|
||||||
if (jsonPrimitive.isBoolean()) return jsonPrimitive.getAsBoolean();
|
if (jsonPrimitive.isBoolean()) {
|
||||||
else if (jsonPrimitive.isNumber()) return jsonPrimitive.getAsNumber().intValue();
|
return jsonPrimitive.getAsBoolean();
|
||||||
else if (jsonPrimitive.isString()) return jsonPrimitive.getAsString();
|
} else if (jsonPrimitive.isNumber()) {
|
||||||
else {
|
double d = jsonPrimitive.getAsDouble();
|
||||||
|
if (d == Math.rint(d)) {
|
||||||
|
return (int) d;
|
||||||
|
} else {
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
} else if (jsonPrimitive.isString()) {
|
||||||
|
return jsonPrimitive.getAsString();
|
||||||
|
} else {
|
||||||
throw new IllegalStateException("Not a JSON Primitive: " + jsonPrimitive);
|
throw new IllegalStateException("Not a JSON Primitive: " + jsonPrimitive);
|
||||||
}
|
}
|
||||||
} else if (jsonElement.isJsonArray()) {
|
} else if (jsonElement.isJsonArray()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue