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.isJsonPrimitive()) {
|
||||
JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonElement;
|
||||
if (jsonPrimitive.isBoolean()) return jsonPrimitive.getAsBoolean();
|
||||
else if (jsonPrimitive.isNumber()) return jsonPrimitive.getAsNumber().intValue();
|
||||
else if (jsonPrimitive.isString()) return jsonPrimitive.getAsString();
|
||||
else {
|
||||
if (jsonPrimitive.isBoolean()) {
|
||||
return jsonPrimitive.getAsBoolean();
|
||||
} else if (jsonPrimitive.isNumber()) {
|
||||
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);
|
||||
}
|
||||
} else if (jsonElement.isJsonArray()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue