List of usage examples for com.google.gwt.json.client JSONValue isBoolean
public JSONBoolean isBoolean()
From source file:org.jboss.errai.common.client.types.JSONTypeHelper.java
License:Apache License
public static Object convert(JSONValue value, Class to, DecodingContext ctx) { JSONValue v;/*from w w w. j ava 2 s . c o m*/ if ((v = value.isString()) != null) { return TypeHandlerFactory.convert(String.class, to, ((JSONString) v).stringValue(), ctx); } else if ((v = value.isNumber()) != null) { return TypeHandlerFactory.convert(Number.class, to, ((JSONNumber) v).doubleValue(), ctx); } else if ((v = value.isBoolean()) != null) { return TypeHandlerFactory.convert(Boolean.class, to, ((JSONBoolean) v).booleanValue(), ctx); } else if ((v = value.isArray()) != null) { List list = new ArrayList(); JSONArray arr = (JSONArray) v; Class cType = to.getComponentType(); while (cType != null && cType.getComponentType() != null) cType = cType.getComponentType(); if (cType == null) cType = to; Object o; for (int i = 0; i < arr.size(); i++) { if ((o = convert(arr.get(i), cType, ctx)) instanceof UnsatisfiedForwardLookup) { ctx.addUnsatisfiedDependency(list, (UnsatisfiedForwardLookup) o); } else { list.add(convert(arr.get(i), cType, ctx)); } } Object t = TypeHandlerFactory.convert(Collection.class, to, list, ctx); ctx.swapDepReference(list, t); return t; } else if ((v = value.isObject()) != null) { JSONObject eMap = (JSONObject) v; Map<Object, Object> m = new UHashMap<Object, Object>(); Object o; Object val; for (String key : eMap.keySet()) { o = key; if (key.startsWith(SerializationParts.EMBEDDED_JSON)) { o = JSONDecoderCli.decode(key.substring(SerializationParts.EMBEDDED_JSON.length()), ctx); } else if (SerializationParts.ENCODED_TYPE.equals(key)) { String className = eMap.get(key).isString().stringValue(); String objId = null; if ((v = eMap.get(SerializationParts.OBJECT_ID)) != null) { objId = v.isString().stringValue(); } boolean ref = false; if (objId != null) { if (objId.charAt(0) == '$') { ref = true; objId = objId.substring(1); } if (ctx.hasObject(objId)) { return ctx.getObject(objId); } else if (ref) { return new UnsatisfiedForwardLookup(objId); } } if (TypeDemarshallers.hasDemarshaller(className)) { o = TypeDemarshallers.getDemarshaller(className).demarshall(eMap, ctx); if (objId != null) ctx.putObject(objId, o); return o; } else { throw new RuntimeException("no available demarshaller: " + className); } } val = JSONDecoderCli.decode(eMap.get(key), ctx); boolean commit = true; if (o instanceof UnsatisfiedForwardLookup) { ctx.addUnsatisfiedDependency(m, (UnsatisfiedForwardLookup) o); if (!(val instanceof UnsatisfiedForwardLookup)) { ((UnsatisfiedForwardLookup) o).setVal(val); } commit = false; } if (val instanceof UnsatisfiedForwardLookup) { ((UnsatisfiedForwardLookup) val).setKey(o); ctx.addUnsatisfiedDependency(m, (UnsatisfiedForwardLookup) val); commit = false; } if (commit) { m.put(o, JSONDecoderCli.decode(eMap.get(key), ctx)); } } return TypeHandlerFactory.convert(Map.class, to, m, ctx); } return null; }
From source file:org.jbpm.console.ng.df.client.filter.FilterSettingsJSONMarshaller.java
License:Apache License
public FilterSettings fromJsonString(String jsonString) { DisplayerSettings displayerSettings = _displayerJsonMarshaller.fromJsonString(jsonString); FilterSettings tableSettings = FilterSettings.cloneFrom(displayerSettings); JSONObject parseResult = JSONParser.parseStrict(jsonString).isObject(); if (parseResult != null) { JSONValue value = parseResult.get(TABLE_NAME); tableSettings.setTableName(/* www . j a v a2 s . c om*/ value != null && value.isString() != null ? value.isString().stringValue() : null); value = parseResult.get(TABLE_DESCR); tableSettings.setTableDescription( value != null && value.isString() != null ? value.isString().stringValue() : null); value = parseResult.get(EDIT_ENABLED); tableSettings.setEditable( value != null && value.isBoolean() != null ? value.isBoolean().booleanValue() : true); } return tableSettings; }
From source file:org.jbpm.formbuilder.client.JsonLoadInput.java
License:Apache License
private static Object asActualValue(JSONValue value) { if (value.isArray() != null) { JSONArray arr = value.isArray(); List<Object> retval = new ArrayList<Object>(); for (int index = 0; index < arr.size(); index++) { JSONValue subValue = arr.get(index); retval.add(asActualValue(subValue)); }//from w w w. ja v a 2s . c om return retval; } else if (value.isBoolean() != null) { return String.valueOf(value.isBoolean().booleanValue()); } else if (value.isNull() != null) { return null; } else if (value.isNumber() != null) { return String.valueOf(value.isNumber().doubleValue()); } else if (value.isString() != null) { return value.isString().stringValue(); } else if (value.isObject() != null) { return toFormData(value.isObject()); } return null; }
From source file:org.lirazs.gbackbone.client.core.data.Options.java
License:Apache License
public Options(JSONValue jsonObject) { JSONObject object = jsonObject.isObject(); if (object != null) { for (String s : object.keySet()) { JSONValue jsonValue = object.get(s); Object value = jsonValue; JSONNumber number = jsonValue.isNumber(); if (number != null) { if (number.toString().contains(".")) { value = number.doubleValue(); } else { value = (int) number.doubleValue(); }//from w w w. j av a 2 s .c o m } JSONBoolean jsonBoolean = jsonValue.isBoolean(); if (jsonBoolean != null) value = jsonBoolean.booleanValue(); JSONNull jsonNull = jsonValue.isNull(); if (jsonNull != null) value = null; JSONString jsonString = jsonValue.isString(); if (jsonString != null) value = jsonString.stringValue(); put(s, value); } } }
From source file:org.nuxeo.ecm.platform.gwt.client.model.Document.java
License:Open Source License
public boolean getBooleanProperty(String schema, String property, boolean defaultValue) { JSONValue v = getProperty(schema, property); if (v != null && v.isString() != null) { return v.isBoolean().booleanValue(); }//from www . j a v a 2 s .c o m return defaultValue; }
From source file:org.nuxeo.ecm.platform.gwt.client.model.DocumentRef.java
License:Open Source License
public static DocumentRef fromJSON(JSONObject json) { DocumentRef doc = new DocumentRef(); JSONValue val = json.get("id"); if (val != null) { doc.id = val.toString(); }/* w ww. j ava2 s .c om*/ val = json.get("title"); if (val != null) { doc.title = val.toString(); } val = json.get("type"); if (val != null) { doc.type = val.toString(); } val = json.get("parentId"); if (val != null) { doc.parentId = val.toString(); } val = json.get("name"); if (val != null) { doc.name = val.toString(); } val = json.get("isFolder"); if (val != null) { JSONBoolean b = val.isBoolean(); doc.isFolder = b != null ? b.booleanValue() : false; } return doc; }
From source file:org.onebusaway.webapp.gwt.common.rpc.JsonLibrary.java
License:Apache License
public static Boolean getJsonBoolean(JSONObject object, String key) { JSONValue value = object.get(key); if (value == null) return null; JSONBoolean b = value.isBoolean(); if (b == null) return null; return new Boolean(b.booleanValue()); }
From source file:org.opencms.acacia.client.widgets.complex.CmsDataViewClientWidget.java
License:Open Source License
/** * Checks if a property in a JSON object is either the boolean value 'true' or a string representation of that value.<p> * * @param obj the JSON object/*from www . java 2 s . com*/ * @param property the property name * @return true if the value represents the boolean 'true' */ private boolean isTrue(JSONObject obj, String property) { JSONValue val = obj.get(property); if (val == null) { return false; } boolean stringTrue = ((val.isString() != null) && Boolean.parseBoolean(val.isString().stringValue())); boolean boolTrue = ((val.isBoolean() != null) && val.isBoolean().booleanValue()); return stringTrue || boolTrue; }
From source file:org.openremote.modeler.client.gxtextends.NestedJsonLoadResultReader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a2s . c om*/ public D read(Object loadConfig, Object data) { JSONObject jsonRoot = null; if (data instanceof JavaScriptObject) { jsonRoot = new JSONObject((JavaScriptObject) data); } else { jsonRoot = (JSONObject) JSONParser.parse((String) data); } // You can specify root using dot separate. eg, vendors.vendor String[] roots = myModelType.getRoot().split("\\."); JSONValue rootValue = null; JSONArray root = null; for (int i = 0; i < roots.length; i++) { rootValue = jsonRoot.get(roots[i]); if (i == roots.length - 1) { if (rootValue instanceof JSONObject) { root = new JSONArray(); root.set(0, rootValue); } else { root = (JSONArray) rootValue; } } else { jsonRoot = (JSONObject) jsonRoot.get(roots[i]); } } int size = root.size(); ArrayList<ModelData> models = new ArrayList<ModelData>(); for (int i = 0; i < size; i++) { JSONObject obj = (JSONObject) root.get(i); ModelData model = newModelInstance(); for (int j = 0; j < myModelType.getFieldCount(); j++) { DataField field = myModelType.getField(j); String name = field.getName(); Class type = field.getType(); String map = field.getMap() != null ? field.getMap() : field.getName(); JSONValue value = obj.get(map); if (value == null) { continue; } if (value.isArray() != null) { // nothing } else if (value.isBoolean() != null) { model.set(name, value.isBoolean().booleanValue()); } else if (value.isNumber() != null) { if (type != null) { Double d = value.isNumber().doubleValue(); if (type.equals(Integer.class)) { model.set(name, d.intValue()); } else if (type.equals(Long.class)) { model.set(name, d.longValue()); } else if (type.equals(Float.class)) { model.set(name, d.floatValue()); } else { model.set(name, d); } } else { // convert no type number to string. model.set(name, value.isNumber().toString()); } } else if (value.isObject() != null) { // nothing } else if (value.isString() != null) { String s = value.isString().stringValue(); if (type != null) { if (type.equals(Date.class)) { if (field.getFormat().equals("timestamp")) { Date d = new Date(Long.parseLong(s) * 1000); model.set(name, d); } else { DateTimeFormat format = DateTimeFormat.getFormat(field.getFormat()); Date d = format.parse(s); model.set(name, d); } } } else { model.set(name, s); } } else if (value.isNull() != null) { model.set(name, null); } } models.add(model); } int totalCount = models.size(); if (myModelType.getTotalName() != null) { totalCount = getTotalCount(jsonRoot); } return (D) createReturnData(loadConfig, models, totalCount); }
From source file:org.sigmah.offline.status.ApplicationStateManager.java
License:Open Source License
private void updateStatus() { final RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, "sigmah/online.nocache.json"); try {//from www . j a v a 2 s. c o m requestBuilder.sendRequest(null, new RequestCallback() { @Override public void onResponseReceived(com.google.gwt.http.client.Request request, Response response) { if (response != null && response.getText() != null && !response.getText().isEmpty()) { try { final JSONValue value = JSONParser.parseStrict(response.getText()); final JSONObject object = value.isObject(); if (object != null) { final JSONValue onlineObject = object.get("online"); final JSONBoolean online = onlineObject.isBoolean(); setOnline(online != null && online.booleanValue()); } else { setOnline(false); } } catch (JSONException ex) { setOnline(false); Log.error( "An error occured while parsing the JSON string: '" + response.getText() + "'.", ex); } } else { setOnline(false); } } @Override public void onError(com.google.gwt.http.client.Request request, Throwable exception) { setOnline(false); } }); } catch (RequestException ex) { setOnline(false); Log.error("An error occured while checking the connection state.", ex); } }