List of usage examples for com.google.gson JsonPrimitive getAsBigDecimal
@Override
public BigDecimal getAsBigDecimal()
From source file:org.eclipse.smarthome.automation.parser.gson.internal.ConfigurationDeserializer.java
License:Open Source License
@Override public Configuration deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Configuration configuration = new Configuration(); JsonObject jo = (JsonObject) json;//from ww w .j av a 2 s .c o m for (Entry<String, JsonElement> e : jo.entrySet()) { JsonPrimitive value = e.getValue().getAsJsonPrimitive(); if (value.isString()) { configuration.put(e.getKey(), value.getAsString()); } else if (value.isNumber()) { configuration.put(e.getKey(), value.getAsBigDecimal()); } else if (value.isBoolean()) { configuration.put(e.getKey(), value.getAsBoolean()); } } return configuration; }
From source file:org.eclipse.smarthome.config.core.ConfigurationDeserializer.java
License:Open Source License
private Object deserialize(JsonPrimitive primitive) { if (primitive.isString()) { return primitive.getAsString(); } else if (primitive.isNumber()) { return primitive.getAsBigDecimal(); } else if (primitive.isBoolean()) { return primitive.getAsBoolean(); } else {//from w w w . j ava2s. c o m throw new IllegalArgumentException("Unsupported primitive: " + primitive); } }
From source file:org.eel.kitchen.jsonschema.GsonProvider.java
License:Open Source License
private static JsonNode gsonToValueNode(final JsonPrimitive primitive) { if (primitive.isBoolean()) return factory.booleanNode(primitive.getAsBoolean()); if (primitive.isNumber()) return toNumberNode(primitive.getAsBigDecimal()); // Can only be a string,now return factory.textNode(primitive.getAsString()); }
From source file:org.i3xx.step.uno.impl.util.GsonHashMapDeserializer.java
License:Apache License
private Object handlePrimitive(JsonPrimitive json) { if (json.isBoolean()) return json.getAsBoolean(); else if (json.isString()) return json.getAsString(); else {/*from w ww . j a v a 2s.co m*/ //System.out.println("GND handlePrimitive: "+json.getAsString()); BigDecimal bigDec = json.getAsBigDecimal(); if (json.getAsString().indexOf('.') == -1) { // Find out if it is an int type try { //System.out.println("GND: "+bigDec.toPlainString()); /* bigDec.toBigIntegerExact(); try { return bigDec.intValueExact(); } catch(ArithmeticException e) {} */ return bigDec.longValue(); } catch (ArithmeticException e) { } } // Just return it as a double return bigDec.doubleValue(); } }
From source file:org.nordapp.web.util.GsonHashMapDeserializer.java
License:Apache License
private Object handlePrimitive(JsonPrimitive json) { if (json.isBoolean()) return json.getAsBoolean(); else if (json.isString()) return json.getAsString(); else {//from w w w . j a v a 2 s.c o m BigDecimal bigDec = json.getAsBigDecimal(); if (json.getAsString().indexOf('.') == -1) { // Find out if it is an int type try { return bigDec.longValue(); } catch (ArithmeticException e) { } } // Just return it as a double return bigDec.doubleValue(); } }