Search in sources :

Example 1 with LazilyParsedNumber

use of com.massivecraft.massivecore.xlib.gson.internal.LazilyParsedNumber in project MassiveCore by MassiveCraft.

the class GsonMongoConverter method gson2MongoPrimitive.

public static Object gson2MongoPrimitive(JsonElement inElement) {
    if (inElement.isJsonNull())
        return null;
    JsonPrimitive in = inElement.getAsJsonPrimitive();
    if (in.isBoolean()) {
        return in.getAsBoolean();
    }
    if (in.isNumber()) {
        Number number = in.getAsNumber();
        boolean floating;
        if (number instanceof LazilyParsedNumber) {
            floating = StringUtils.contains(number.toString(), '.');
        } else {
            floating = (number instanceof Double || number instanceof Float);
        }
        if (floating) {
            return number.doubleValue();
        } else {
            return number.longValue();
        }
    }
    if (in.isString()) {
        return in.getAsString();
    }
    throw new IllegalArgumentException("Unsupported value type for: " + in);
}
Also used : LazilyParsedNumber(com.massivecraft.massivecore.xlib.gson.internal.LazilyParsedNumber) JsonPrimitive(com.massivecraft.massivecore.xlib.gson.JsonPrimitive) LazilyParsedNumber(com.massivecraft.massivecore.xlib.gson.internal.LazilyParsedNumber)

Aggregations

JsonPrimitive (com.massivecraft.massivecore.xlib.gson.JsonPrimitive)1 LazilyParsedNumber (com.massivecraft.massivecore.xlib.gson.internal.LazilyParsedNumber)1