List of usage examples for com.google.gwt.json.client JSONValue isNumber
public JSONNumber isNumber()
From source file:com.hunchee.haystack.client.utils.JsonConverter.java
License:Open Source License
/** * Decodes a JSONObject to a map.// www .j a v a 2 s . c om * * @param jso the JSONObject * @return the map */ public static Map<String, Object> decode(JSONObject jso) { Map<String, Object> map = new LinkedHashMap<String, Object>(); for (String key : jso.keySet()) { JSONValue j = jso.get(key); if (j.isObject() != null) { map.put(key, decode(j.isObject())); } else if (j.isArray() != null) { map.put(key, decodeToList(j.isArray())); } else if (j.isBoolean() != null) { map.put(key, j.isBoolean().booleanValue()); } else if (j.isNumber() != null) { map.put(key, j.isNumber().doubleValue()); } else if (j.isString() != null) { //map.put(key, decodeValue(j.isString().stringValue())); map.put(key, j.isString().stringValue()); } } return map; }
From source file:com.hunchee.haystack.client.utils.JsonConverter.java
License:Open Source License
protected static List<Object> decodeToList(JSONArray array) { List<Object> list = new ArrayList<Object>(); for (int i = 0; i < array.size(); i++) { JSONValue v = array.get(i); if (v.isObject() != null) { list.add(decode(v.isObject())); } else if (v.isArray() != null) { list.add(decodeToList(v.isArray())); } else if (v.isNull() != null) { list.add(null);/* w ww .ja v a 2 s . co m*/ } else if (v.isNumber() != null) { list.add(v.isNumber().doubleValue()); } else if (v.isBoolean() != null) { list.add(v.isBoolean().booleanValue()); } else if (v.isString() != null) { // list.add(decodeValue(v.isString().stringValue())); list.add(v.isString().stringValue()); } } return list; }
From source file:com.kk_electronic.kkportal.core.rpc.jsonformat.JsonDate.java
License:Open Source License
@Override public Date fromJson(JSONValue jsonValue, List<Class<?>> subtypes, FrameEncoder<JSONValue> encoder) throws UnableToDeserialize { if (jsonValue.isNull() != null) return null; if (jsonValue.isNumber() == null) throw new UnableToDeserialize("Expected Json Number"); JSONNumber o = jsonValue.isNumber(); return new Date((long) (o.doubleValue())); }
From source file:com.kk_electronic.kkportal.core.rpc.jsonformat.JsonDouble.java
License:Open Source License
@Override public Double fromJson(JSONValue jsonValue, List<Class<?>> subtypes, FrameEncoder<JSONValue> encoder) throws UnableToDeserialize { JSONNumber number = jsonValue.isNumber(); if (number == null) throw new UnableToDeserialize("Expected json number"); return number.doubleValue(); }
From source file:com.kk_electronic.kkportal.core.rpc.jsonformat.JsonInteger.java
License:Open Source License
@Override public Integer fromJson(JSONValue jsonValue, List<Class<?>> subtypes, FrameEncoder<JSONValue> encoder) throws UnableToDeserialize { JSONNumber number = jsonValue.isNumber(); if (number == null) throw new UnableToDeserialize("Expected json number"); return (int) number.doubleValue(); }
From source file:com.kk_electronic.kkportal.core.rpc.jsonformat.JsonLong.java
License:Open Source License
@Override public Long fromJson(JSONValue jsonValue, List<Class<?>> subtypes, FrameEncoder<JSONValue> encoder) throws UnableToDeserialize { JSONNumber number = jsonValue.isNumber(); if (number == null) throw new UnableToDeserialize("Expected json number"); return (long) number.doubleValue(); }
From source file:com.kk_electronic.kkportal.core.rpc.SimpleEncoder.java
License:Open Source License
private static Object convert(JSONValue y, ObjectHelper objectHelper) { if (y.isArray() != null) return convert(y.isArray(), objectHelper); if (y.isObject() != null) return convert(y.isObject(), objectHelper); if (y.isBoolean() != null) return y.isBoolean().booleanValue(); if (y.isString() != null) return y.isString().stringValue(); if (y.isNumber() != null) return y.isNumber().doubleValue(); if (y.isNull() != null) return null; throw new RuntimeException("Could not convert"); }
From source file:com.mcherm.zithiacharsheet.client.model.JSONDeserializer.java
License:Apache License
protected void updateFromField(JSONObject parent, String fieldName, SettableIntValue settableIntValue) { JSONValue valueValue = notNull(parent.get(fieldName)); JSONNumber valueNum = notNull(valueValue.isNumber()); int valueInt = (int) valueNum.doubleValue(); settableIntValue.setValue(valueInt); }
From source file:com.mcherm.zithiacharsheet.client.model.JSONDeserializer.java
License:Apache License
protected void updateFromField(JSONObject parent, String fieldName, TweakableIntValue tweakableIntValue) { JSONValue value = parent.get(fieldName); if (value == null) { tweakableIntValue.setAdjustments(null, null); } else {//from ww w .j a v a 2s .c o m JSONObject obj = notNull(value.isObject()); final Integer overrideInt; final Integer modifierInt; JSONValue overrideValue = obj.get("override"); if (overrideValue == null) { overrideInt = null; } else { JSONNumber overrideNum = notNull(overrideValue.isNumber()); overrideInt = Integer.valueOf((int) overrideNum.doubleValue()); } JSONValue modifierValue = obj.get("modifier"); if (modifierValue == null) { modifierInt = null; } else { JSONNumber modifierNum = notNull(modifierValue.isNumber()); modifierInt = Integer.valueOf((int) modifierNum.doubleValue()); } tweakableIntValue.setAdjustments(overrideInt, modifierInt); } }
From source file:com.moesol.gwt.maps.client.tms.FeatureReader.java
License:Open Source License
private double getDoubleProperty(String propertyName, JSONObject obj) { JSONValue jsonValue = obj.get(propertyName); if (jsonValue != null) { JSONNumber jsonNumber = jsonValue.isNumber(); if (jsonNumber != null) { return jsonNumber.doubleValue(); }/*from w w w . j av a 2 s .com*/ } return 0.0; }