Example usage for com.google.gson.internal LazilyParsedNumber toString

List of usage examples for com.google.gson.internal LazilyParsedNumber toString

Introduction

In this page you can find the example usage for com.google.gson.internal LazilyParsedNumber toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:com.jayway.jsonpath.internal.spi.json.GsonJsonProvider.java

License:Apache License

private static Number unwrapNumber(Number n) {
    Number unwrapped;/* w  w w .  j a va2s.  c  o  m*/

    if (n instanceof LazilyParsedNumber) {
        LazilyParsedNumber lpn = (LazilyParsedNumber) n;
        BigDecimal bigDecimal = new BigDecimal(lpn.toString());
        if (bigDecimal.scale() <= 0) {
            if (bigDecimal.compareTo(new BigDecimal(Integer.MAX_VALUE)) <= 0) {
                unwrapped = bigDecimal.intValue();
            } else {
                unwrapped = bigDecimal.longValue();
            }
        } else {
            unwrapped = bigDecimal.doubleValue();
        }
    } else {
        unwrapped = n;
    }
    return unwrapped;
}

From source file:com.jayway.jsonpath.spi.json.GsonJsonProvider.java

License:Apache License

private static Number unwrapNumber(final Number n) {
    Number unwrapped;//from  w  w  w . j  a  v a2  s.c o m

    if (n instanceof LazilyParsedNumber) {
        LazilyParsedNumber lpn = (LazilyParsedNumber) n;
        BigDecimal bigDecimal = new BigDecimal(lpn.toString());
        if (bigDecimal.scale() <= 0) {
            if (bigDecimal.compareTo(new BigDecimal(Integer.MAX_VALUE)) <= 0) {
                unwrapped = bigDecimal.intValue();
            } else {
                unwrapped = bigDecimal.longValue();
            }
        } else {
            unwrapped = bigDecimal.doubleValue();
        }
    } else {
        unwrapped = n;
    }

    return unwrapped;
}

From source file:com.tsc9526.monalisa.tools.json.MelpJson.java

License:Open Source License

public static Object primitive(JsonPrimitive e) {
    if (e.isNumber()) {
        Number n = e.getAsNumber();
        if (n instanceof LazilyParsedNumber) {
            LazilyParsedNumber ln = (LazilyParsedNumber) n;
            String value = ln.toString();
            if (value.indexOf('.') >= 0) {
                return ln.doubleValue();
            } else {
                return ln.longValue();
            }/*from   ww w. j a  v a  2 s . c o  m*/
        } else {
            return n;
        }
    } else if (e.isBoolean()) {
        return e.getAsBoolean();
    } else {
        return e.getAsString();
    }
}