if ((jsonObject = jsonValue.isObject()) == null) { Window.alert("Error parsing the JSON"); if ((jsonObject = jsonValue.isObject()) == null) { Window.alert("Error parsing the JSON"); if ((jsonString = jsonValue.isString()) == null) { Window.alert("Error parsing the JSON"); Window.alert(jsonString.stringValue()); // Finally!
public Object deserialize(JSONValue jsonValue) { JSONObject obj = jsonValue.isObject(); if (obj != null) { if (obj.containsKey("class") && obj.get("class").isString() != null) { return serializer.deSerialize(jsonValue, obj.get("class").isString().stringValue()); } } throw new IllegalArgumentException("Json string must contain \"class\" key."); }
public Map<String, InputData> decodeInputs(JSONValue json) throws FormEncodingException { Map<String, InputData> retval = new HashMap<String, InputData>(); if (json != null && json.isObject() != null) { for (String key : json.isObject().keySet()) { JSONValue value = json.isObject().get(key); if (value.isObject() != null) { JSONObject jsonObj = value.isObject(); retval.put(key, (InputData) decode(asMap(jsonObj))); } } } return retval; }
/** * Get a child JSON object from a parent JSON object. * * @param jsonObject The parent JSON object. * @param key The name of the child object. * @return Returns the child JSON object if it could be found, or null if the value was null. * @throws JSONException In case something went wrong while searching for the child. */ public static JSONObject getChild(JSONObject jsonObject, String key) throws JSONException { checkArguments(jsonObject, key); JSONValue value = jsonObject.get(key); if (value != null) { if (value.isObject() != null) { return value.isObject(); } else if (value.isNull() != null) { return null; } throw new JSONException("Child is not a JSONObject, but a: " + value.getClass()); } return null; }
private Feature createFeature(JSONObject jsonObject, FeaturesSupported layer) { String id = null; if (jsonObject.containsKey("id")) { id = JsonService.getStringValue(jsonObject, "id"); } else { JSONValue value = properties.get(name); Attribute attribute; if (value.isBoolean() != null) { } else if (value.isNumber() != null) { attribute = new AttributeImpl(JsonService.getDoubleValue(properties, name)); } else if (value.isObject() != null) { attribute = new AttributeImpl(JsonService.getGeometryValue(properties, name)); } else {
protected <Y> void parseSingularJsonReference( X targetEntity, ErraiSingularAttribute<? super X, Y> attr, JSONValue attrJsonValue, ErraiEntityManager eem) { if (attrJsonValue == null || attrJsonValue.isNull() != null) return; 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); }
public static JSONValue unwrapJson( JSONValue json ) { if( json == null ) return null; JSONObject obj = json.isObject(); if( obj == null ) return null; JSONValue v = obj.get( "v" ); if( v == null ) return null; JSONString vs = v.isString(); if( vs == null ) return null; if( !vs.stringValue().equals( "v2" ) ) return null; return obj.get( "data" ); }
public Map<String, OutputData> decodeOutputs(JSONValue json) throws FormEncodingException { Map<String, OutputData> retval = new HashMap<String, OutputData>(); if (json != null && json.isObject() != null) { for (String key : json.isObject().keySet()) { JSONValue value = json.isObject().get(key); if (value.isObject() != null) { JSONObject jsonObj = value.isObject(); retval.put(key, (OutputData) decode(asMap(jsonObj))); } } } return retval; }
public static RefactoringResultDto fromJson(JSONValue jsonVal) { if (jsonVal == null) { return null; } JSONObject json= jsonVal.isObject(); RefactoringResultDto result= new RefactoringResultDto(); JSONValue jsonrefactoringStatusJson = json.get("refactoringStatus"); if (jsonrefactoringStatusJson != null && !(jsonrefactoringStatusJson.isNull() != null)) { org.eclipse.che.jdt.ls.extension.api.dto.RefactoringStatus jsonrefactoringStatusVal = RefactoringStatusDto.fromJson((JSONObject)jsonrefactoringStatusJson);; result.setRefactoringStatus((org.eclipse.che.jdt.ls.extension.api.dto.RefactoringStatus)jsonrefactoringStatusVal); } JSONValue jsoncheWorkspaceEditJson = json.get("cheWorkspaceEdit"); if (jsoncheWorkspaceEditJson != null && !(jsoncheWorkspaceEditJson.isNull() != null)) { org.eclipse.che.jdt.ls.extension.api.dto.CheWorkspaceEdit jsoncheWorkspaceEditVal = CheWorkspaceEditDto.fromJson((JSONObject)jsoncheWorkspaceEditJson);; result.setCheWorkspaceEdit((org.eclipse.che.jdt.ls.extension.api.dto.CheWorkspaceEdit)jsoncheWorkspaceEditVal); } return result; } }
public static JSONValue unwrapJson( JSONValue json ) { if( json == null ) return null; JSONObject obj = json.isObject(); if( obj == null ) return null; JSONValue v = obj.get( "v" ); if( v == null ) return null; JSONString vs = v.isString(); if( vs == null ) return null; if( !vs.stringValue().equals( "v2" ) ) return null; return obj.get( "data" ); }
@Override public Map<K, V> deserialize(final JSONValue jsonValue) { if (jsonValue == null || jsonValue.isNull() != null) { return null; } final JSONObject jsonObject = jsonValue.isObject(); if (jsonObject == null) { throw new GWTPojoSerializerException("Unable to deserialize " + jsonValue.toString() + " as Map<?, ?>"); } final Map<K, V> map = new HashMap<K, V>(); for (String keyString : jsonObject.keySet()) { final K key = kSerializer.deserialize(new JSONString(keyString)); final V value = vSerializer.deserialize(jsonObject.get(keyString)); map.put(key, value); } return map; } }
@Override @Nullable protected Settings parse(@Nonnull final Response response) { RemoteSettings result = null; if (response.getText() != null && !"".equals(response.getText())) { // TODO add appropriate comment - unwrap JSONValue rootElement = new JSONObject(convertFromJSON(response.getText())).get(SETTINGS_KEY); if (rootElement != null && rootElement.isObject() != null) { result = (RemoteSettings) rootElement.isObject().getJavaScriptObject(); } } return result != null ? Converter.convertToSettings(result) : null; }
@Override public boolean supportsContent(String content) { try { JSONValue jsonValue = JSONParser.parseStrict( content ); JSONObject jsonObject; if ((jsonObject = jsonValue.isObject()) == null) return false; jsonValue = jsonObject.get( "handler" ); if (jsonValue.isString() == null) return false; return jsonValue.isString().stringValue().equals( "handledByPlaceManagerFormProvider" ); } catch ( Exception e ) { } return false; }
private static Map<String, JSONValue> readPreferencesFromJson(String jsonPreferences) { Map<String, JSONValue> result = new HashMap<>(); JSONValue parsed = JSONParser.parseStrict(jsonPreferences); JSONObject jsonObj = parsed.isObject(); if (jsonObj != null) { jsonObj.keySet().forEach(key -> result.put(key, jsonObj.get(key))); } return result; } }
protected final void validateAttributes(final JSONObject json, final IFactory<?> factory, final String type, final ValidationContext ctx) throws ValidationException final JSONValue aval = json.get("attributes"); final JSONObject aobj = aval.isObject(); final JSONValue jval = aobj.get(attrName); if (((jval == null) || (jval.isNull() != null))) atyp.validate(aobj.get(attrName), ctx);
@Override public boolean supportsContent(String content) { try { JSONValue jsonValue = JSONParser.parseStrict( content ); JSONObject jsonObject; if ((jsonObject = jsonValue.isObject()) == null) return false; jsonValue = jsonObject.get( "handler" ); if (jsonValue.isString() == null) return false; return jsonValue.isString().stringValue().equals( "handledByPlaceManagerFormProvider" ); } catch ( Exception e ) { } return false; }
private static Map<String, JSONValue> readPropertiesFromJson(String jsonProperties) { Map<String, JSONValue> result = new HashMap<>(); JSONValue parsed = JSONParser.parseStrict(jsonProperties); JSONObject jsonObj = parsed.isObject(); if (jsonObj != null) { for (String key : jsonObj.keySet()) { JSONValue jsonValue = jsonObj.get(key); result.put(key, jsonValue); } } return result; } }