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 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 ArchetypeOutputImpl fromJsonObjectInt(JSONValue jsonValue, boolean copyJsons) { if (jsonValue == null || jsonValue.isNull() != null) { return null; } ArchetypeOutputImpl dto = new ArchetypeOutputImpl(); JSONObject json = jsonValue.isObject(); if (json.containsKey("state")) { JSONValue stateIn = json.get("state"); org.eclipse.che.plugin.maven.shared.dto.ArchetypeOutput.State stateOut = org.eclipse.che.plugin.maven.shared.dto.ArchetypeOutput.State.valueOf(stateIn.isString().stringValue()); dto.setState(stateOut); } if (json.containsKey("output")) { JSONValue outputIn = json.get("output"); String outputOut = outputIn.isString() != null ? outputIn.isString().stringValue() : null; dto.setOutput(outputOut); } return dto; }
public static YamlDTOImpl fromJsonObjectInt(JSONValue jsonValue, boolean copyJsons) { if (jsonValue == null || jsonValue.isNull() != null) { return null; } YamlDTOImpl dto = new YamlDTOImpl(); JSONObject json = jsonValue.isObject(); if (json.containsKey("schemas")) { JSONValue schemasIn = json.get("schemas"); java.util.Map<java.lang.String, java.lang.String> schemasOut = null; if (schemasIn != null && schemasIn.isNull() == null) { schemasOut = new java.util.HashMap<java.lang.String, java.lang.String>(); java.util.Set<String> keySet0 = schemasIn.isObject().keySet(); for (String key0 : keySet0) { JSONValue schemasIn_ = schemasIn.isObject().get(key0); String schemasOut_ = schemasIn_.isString() != null ? schemasIn_.isString().stringValue() : null; schemasOut.put(key0, schemasOut_); } } dto.setSchemas(schemasOut); } return dto; }
if (json.containsKey("version")) { JSONValue versionIn = json.get("version"); String versionOut = versionIn.isString() != null ? versionIn.isString().stringValue() : null; dto.setVersion(versionOut); if (json.containsKey("repository")) { JSONValue repositoryIn = json.get("repository"); String repositoryOut = repositoryIn.isString() != null ? repositoryIn.isString().stringValue() : null; dto.setRepository(repositoryOut); if (json.containsKey("properties")) { JSONValue propertiesIn = json.get("properties"); java.util.Map<java.lang.String, java.lang.String> propertiesOut = null; if (propertiesIn != null && propertiesIn.isNull() == null) { propertiesOut = new java.util.HashMap<java.lang.String, java.lang.String>(); java.util.Set<String> keySet0 = propertiesIn.isObject().keySet(); for (String key0 : keySet0) { JSONValue propertiesIn_ = propertiesIn.isObject().get(key0); String propertiesOut_ = propertiesIn_.isString() != null ? propertiesIn_.isString().stringValue() : null; propertiesOut.put(key0, propertiesOut_); if (json.containsKey("artifactId")) { JSONValue artifactIdIn = json.get("artifactId"); String artifactIdOut = artifactIdIn.isString() != null ? artifactIdIn.isString().stringValue() : null; if (json.containsKey("groupId")) { JSONValue groupIdIn = json.get("groupId"); String groupIdOut = groupIdIn.isString() != null ? groupIdIn.isString().stringValue() : null;
if (json.containsKey("name")) { JSONValue nameIn = json.get("name"); String nameOut = nameIn.isString() != null ? nameIn.isString().stringValue() : null; dto.setName(nameOut); if (json.containsKey("port")) { JSONValue portIn = json.get("port"); int portOut = (int)portIn.isNumber().doubleValue(); dto.setPort(portOut); if (json.containsKey("type")) { JSONValue typeIn = json.get("type"); String typeOut = typeIn.isString() != null ? typeIn.isString().stringValue() : null; dto.setType(typeOut); if (json.containsKey("connectionProperties")) { JSONValue connectionPropertiesIn = json.get("connectionProperties"); java.util.Map<java.lang.String, java.lang.String> connectionPropertiesOut = null; if (connectionPropertiesIn != null && connectionPropertiesIn.isNull() == null) { connectionPropertiesOut = new java.util.HashMap<java.lang.String, java.lang.String>(); java.util.Set<String> keySet0 = connectionPropertiesIn.isObject().keySet(); for (String key0 : keySet0) { JSONValue connectionPropertiesIn_ = connectionPropertiesIn.isObject().get(key0); String connectionPropertiesOut_ = connectionPropertiesIn_.isString() != null ? connectionPropertiesIn_.isString().stringValue() : null; connectionPropertiesOut.put(key0, connectionPropertiesOut_); if (json.containsKey("host")) { JSONValue hostIn = json.get("host"); String hostOut = hostIn.isString() != null ? hostIn.isString().stringValue() : null;
private void onMessage(JSONObject obj) { if (obj.containsKey("welcome")) { JSONString str = obj.get("welcome").isString(); if (str != null) { addLine("<em><b>" + str.stringValue() + "</b></em>"); } } else if (obj.containsKey("announcement")) { JSONString str = obj.get("announcement").isString(); if (str != null) { addLine("<em>" + str.stringValue() + "</em>"); } } else if (obj.containsKey("message")) { JSONArray arr = obj.get("message").isArray(); if (arr != null && arr.size() >= 2) { JSONString id = arr.get(0).isString(); JSONString msg = arr.get(1).isString(); if (id != null && msg != null) { addLine("<b>" + id.stringValue() + ":</b> " + msg.stringValue()); } } } }
public static void dispatchJSON(JavaScriptObject jsonObj, JSONHandler handler) { JSONObject obj = new JSONObject(jsonObj); if (obj.isObject() != null) { if (obj.containsKey("err_code")) { handler.onError(new Double(obj.get("err_code").isNumber().doubleValue()).intValue(), obj.get("err_msg").isString().stringValue()); return; } } handler.onResponse(jsonObj); }
private static TimeseriesRenderingOptions createRenderingOptions(String options) { if (options == null) { return new TimeseriesRenderingOptions(); } TimeseriesRenderingOptions tsOptions = new TimeseriesRenderingOptions(); JSONObject tsRenderingOptions = new JSONObject(parseUntrustedJson(options)); if (tsRenderingOptions.containsKey("color")) { JSONString color = tsRenderingOptions.get("color").isString(); tsOptions.setColor(color.stringValue()); } if (tsRenderingOptions.containsKey("lineWidth")) { JSONNumber lineWidth = tsRenderingOptions.get("lineWidth").isNumber(); tsOptions.setLineWidth((int)lineWidth.doubleValue()); } return tsOptions; }
@Override public ModelNode get() { ModelNode node; if (contentType.startsWith(APPLICATION_DMR_ENCODED)) { node = ModelNode.fromBase64(payload); } else if (contentType.startsWith(APPLICATION_JSON)) { node = new ModelNode(); JSONObject response = JSONParser.parseLenient(payload).isObject(); JSONString outcome = response.get(OUTCOME).isString(); node.get(OUTCOME).set(outcome.stringValue()); if (outcome.stringValue().equals(SUCCESS)) { if (response.containsKey(RESULT) && response.get(RESULT).isObject() != null) { node.get(RESULT).set(stringify(response.get(RESULT).isObject().getJavaScriptObject(), 2)); } else { node.get(RESULT).set(new ModelNode()); } } else { String failure = extractFailure(response); node.get(FAILURE_DESCRIPTION).set(failure); } } else { node = new ModelNode(); node.get(OUTCOME).set(FAILED); node.get(FAILURE_DESCRIPTION).set("Unable to parse response with content-type " + contentType); } return node; }
assertTrue(jsonObject.containsKey("booleanPrimitive")); assertNotNull(jsonObject.get("booleanPrimitive").isBoolean()); assertFalse(jsonObject.get("booleanPrimitive").isBoolean().booleanValue()); assertTrue(jsonObject.containsKey("booleanObject")); assertSame(JSONNull.getInstance(), jsonObject.get("booleanObject").isNull()); assertTrue(jsonObject.containsKey("bytePrimitive")); assertSame(JSONNull.getInstance(), jsonObject.get("byteObject").isNull()); assertTrue(jsonObject.containsKey("characterPrimitive")); assertNotNull(jsonObject.get("characterPrimitive").isString()); assertEquals(String.valueOf('\0'), jsonObject.get("characterPrimitive").isString().stringValue()); assertSame(JSONNull.getInstance(), jsonObject.get("characterObject").isNull()); assertTrue(jsonObject.containsKey("doublePrimitive")); assertTrue(jsonObject.containsKey("floatPrimitive")); assertTrue(jsonObject.containsKey("integerPrimitive")); assertTrue(jsonObject.containsKey("longPrimitive")); assertTrue(jsonObject.containsKey("shortPrimitive")); assertTrue(jsonObject.containsKey("date")); assertNotNull(jsonObject.get("date").isNull()); assertTrue(jsonObject.containsKey("sqlDate")); assertNotNull(jsonObject.get("sqlDate").isNull()); assertTrue(jsonObject.containsKey("time")); assertNotNull(jsonObject.get("time").isNull()); assertTrue(jsonObject.containsKey("timestamp"));