public String getTokenValue( String name ) { JSONValue value = values.get( name ); if( value == null ) return ""; JSONString string = value.isString(); if( string == null ) return ""; String res = string.stringValue(); if( res == null ) return ""; return res; }
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."); }
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; } }
/** * 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 {
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 String getTokenValue( String name ) { JSONValue value = values.get( name ); if( value == null ) return ""; JSONString string = value.isString(); if( string == null ) return ""; String res = string.stringValue(); if( res == null ) return ""; return res; }
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" ); }
public static String getParameterString( JSONObject json, int index ) { if( json == null ) return null; JSONObject prm = getParam( json, index, "java.lang.String" ); return prm.get( "value" ).isString().stringValue(); }
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; } }
@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 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; } }
/** * checks if a certain object value is null. * * @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; }
public void newServiceCall( JSONObject json ) { assert json != null; String serviceName = json.get( "service" ).isString().stringValue(); String interfaceName = json.get( "interface" ).isString().stringValue(); JSONObject call = json.get( "value" ).isObject(); ICallDeserializer<?> deserializer = deserializers.get( getId( serviceName, interfaceName ) ); assert deserializer != null; deserializer.newCall( call ); }