List of usage examples for com.google.gwt.json.client JSONValue isNull
public JSONNull isNull()
From source file:org.geomajas.gwt2.client.service.JsonService.java
License:Open Source License
/** * checks if a certain object value is null. * //from w w w . j a va 2 s .com * @param jsonObject The object to get the key value from. * @param key The name of the key to search the value for. * @throws JSONException In case something went wrong while parsing. */ public static boolean isNullObject(JSONObject jsonObject, String key) throws JSONException { checkArguments(jsonObject, key); JSONValue value = jsonObject.get(key); boolean isNull = false; if (value == null || value.isNull() != null) { isNull = true; } return isNull; }
From source file:org.geomajas.gwt2.plugin.wms.client.service.WmsServiceImpl.java
License:Open Source License
@Override public void getFeatureInfo(ViewPort viewPort, final WmsLayer wmsLayer, Coordinate location, String format, final Callback<List<Feature>, String> callback) { final String url = getFeatureInfoUrl(viewPort, wmsLayer, location, format.toString()); // we can only handle json for now if (!GetFeatureInfoFormat.JSON.toString().equals(format)) { callback.onFailure("Client does not support " + format + " format"); }/*from w ww .j a va2 s . com*/ RequestBuilder builder = requestBuilderFactory.create(RequestBuilder.GET, url); try { builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable e) { callback.onFailure(e.getMessage()); } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { JSONValue jsonValue = JsonService.parse(response.getText()); FeatureCollection featureCollection; if (jsonValue.isObject() != null) { if (wmsLayer instanceof FeaturesSupported) { FeaturesSupported featuresSupported = (FeaturesSupported) wmsLayer; featureCollection = jsonFeatureFactory.createCollection(jsonValue.isObject(), featuresSupported); } else { featureCollection = jsonFeatureFactory.createCollection(jsonValue.isObject(), null); } callback.onSuccess(featureCollection.getFeatures()); } else if (jsonValue.isNull() != null) { callback.onFailure("Response was empty"); } } else { callback.onFailure(response.getText()); } } }); } catch (RequestException e) { // Couldn't connect to server callback.onFailure(e.getMessage()); } }
From source file:org.jboss.errai.common.client.json.JSONDecoderCli.java
License:Apache License
private static Object _decode(JSONValue v, DecodingContext ctx) { if (v.isString() != null) { return v.isString().stringValue(); } else if (v.isNumber() != null) { return v.isNumber().doubleValue(); } else if (v.isBoolean() != null) { return v.isBoolean().booleanValue(); } else if (v.isNull() != null) { return null; } else if (v instanceof JSONObject) { return decodeObject(v.isObject(), ctx); } else if (v instanceof JSONArray) { return decodeList(v.isArray(), ctx); } else {// w w w .jav a 2 s.co m throw new RuntimeException("unknown encoding"); } }
From source file:org.jboss.errai.jpa.client.local.ErraiManagedType.java
License:Apache License
protected <Y> void parseSingularJsonReference(X targetEntity, ErraiSingularAttribute<? super X, Y> attr, JSONValue attrJsonValue, ErraiEntityManager eem) { if (attrJsonValue == null || attrJsonValue.isNull() != null) return;/*from w ww . java 2 s .c om*/ Key<Y, ?> key = (Key<Y, ?>) Key.fromJsonObject(eem, attrJsonValue.isObject(), true); logger.trace(" looking for " + key); Y value = eem.find(key, Collections.<String, Object>emptyMap()); attr.set(targetEntity, value); }
From source file:org.jbpm.formapi.client.form.FormRepresentationDecoderClient.java
License:Apache License
private Object fromJsonValue(JSONValue elem) { if (elem.isString() != null) { return elem.isString().stringValue(); } else if (elem.isNumber() != null) { return elem.isNumber().doubleValue(); } else if (elem.isArray() != null) { return asList(elem.isArray()); } else if (elem.isNull() != null) { return null; } else if (elem.isObject() != null) { return asMap(elem.isObject()); } else {// w w w . j a va2 s . c o m return ""; } }
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 a2s . co m*/ 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(); }// ww w. j a v a 2 s .com } 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.openremote.modeler.client.gxtextends.NestedJsonLoadResultReader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a2 s.c o m*/ 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.sonatype.nexus.gwt.ui.client.table.JSONArrayTableModel.java
License:Open Source License
public Object getCell(int rowIndex, int colIndex) { JSONObject obj = (JSONObject) getRow(rowIndex); JSONValue val = JSONUtil.getValue(obj, props[colIndex]); if (val != null) { if (val.isString() != null) { return val.isString().stringValue(); } else if (val.isBoolean() != null) { return Boolean.valueOf(val.isBoolean().booleanValue()); } else if (val.isNumber() != null) { return new Double(val.isNumber().doubleValue()); } else if (val.isNull() != null) { return null; } else {//from w w w .j a va 2s . co m return val; } } return null; }
From source file:rocket.remoting.client.support.rpc.JsonServiceMethodInvoker.java
License:Apache License
/** * Takes the response and converts the json payload to a java instance using * {@link #deserializeJsonPayload(String)} * //from w w w . j ava2 s. co m * @param request * The request * @param response * The response */ protected void onSuccessfulResponse(final Request request, final Response response) { final AsyncCallback<R> callback = this.getCallback(); R object = null; boolean skipOnFailure = false; try { final String text = response.getText(); final JSONValue jsonValue = JSONParser.parse(text); if (false == jsonValue.isNull() instanceof JSONNull) { object = this.readObject(jsonValue); } // invoke success! after deserializing... skipOnFailure = true; callback.onSuccess(object); } catch (final Throwable caught) { if (false == skipOnFailure) { // invoke failure if anything went wrong. callback.onFailure(caught); } } }