private static JSONObject throwableAsJsonObject(Throwable t) { JSONObject obj = new JSONObject(); if (t != null) { obj.put("type", getJsonString(t.getClass().getName())); obj.put("message", getJsonString(t.getMessage())); obj.put("cause", throwableAsJsonObject(t.getCause())); StackTraceElement[] stackTrace = t.getStackTrace(); if (stackTrace != null && stackTrace.length > 0) { JSONArray arr = new JSONArray(); for (int i = 0; i < stackTrace.length; i++) { arr.set(i, stackTraceElementAsJsonObject(stackTrace[i])); } obj.put("stackTrace", arr); } } return obj; } }
@Override public void onSuccess(LogAppenderDto key) { JSONObject json = (JSONObject) JSONParser.parseLenient(key.getJsonConfiguration()); json.put("minLogSchemaVersion", new JSONNumber(key.getMinLogSchemaVersion())); json.put("maxLogSchemaVersion", new JSONNumber(key.getMaxLogSchemaVersion())); json.put("pluginTypeName", new JSONString(key.getPluginTypeName())); json.put("pluginClassName", new JSONString(key.getPluginClassName())); JSONArray headersStructure = new JSONArray(); for (LogHeaderStructureDto header : key.getHeaderStructure()) { headersStructure.set(headersStructure.size(), new JSONString(header.getValue())); } json.put("headerStructure", headersStructure); ServletHelper.downloadJsonFile(json.toString(), key.getPluginTypeName() + ".json"); } };
@Override public void onSuccess(UserVerifierDto key) { String jsonConfig = key.getJsonConfiguration(); JSONObject json; //Some verifiers (ex:Trustful) has no jsonConfiguration field if (jsonConfig != null && !jsonConfig.isEmpty()) { json = (JSONObject) JSONParser.parseLenient(jsonConfig); } else { json = new JSONObject(); } json.put("pluginTypeName", new JSONString(key.getPluginTypeName())); json.put("pluginClassName", new JSONString(key.getPluginClassName())); ServletHelper.downloadJsonFile(json.toString(), key.getPluginTypeName() + ".json"); } };
private static JSONObject logRecordAsJsonObject(LogRecord lr) { JSONObject obj = new JSONObject(); obj.put("level", getJsonString(lr.getLevel().toString())); obj.put("loggerName", getJsonString(lr.getLoggerName())); obj.put("msg", getJsonString(lr.getMessage())); obj.put("timestamp", new JSONString("" + lr.getMillis())); obj.put("thrown", throwableAsJsonObject(lr.getThrown())); return obj; }
public JSONValue toJsonElement() { JSONObject result = new JSONObject(); if (getProjectsToUpdate() == null) { setProjectsToUpdate((java.util.List<java.lang.String>)null); } else { JSONArray projectsToUpdateVal = new JSONArray(); for (java.lang.String projectsToUpdateValX : getProjectsToUpdate()) { JSONValue projectsToUpdateValY = projectsToUpdateValX == null ? JSONNull.getInstance() : new JSONString(projectsToUpdateValX);; projectsToUpdateVal.set(projectsToUpdateVal.size(), projectsToUpdateValY); } result.put("projectsToUpdate", projectsToUpdateVal); } return result; }
public JSONObject toJsonObjectInt(boolean copyJsons) { JSONObject result = new JSONObject(); JSONObject schemasOut = new JSONObject(); this.ensureSchemas(); for (java.util.Map.Entry<String, java.lang.String> entry0 : this.schemas.entrySet()) { java.lang.String schemas_ = entry0.getValue(); JSONValue schemasOut_ = (schemas_ == null) ? JSONNull.getInstance() : new JSONString(schemas_); schemasOut.put(entry0.getKey(), schemasOut_); } result.put("schemas", schemasOut); return result; }
@Override public Object decode(JSONValue value) throws JsonEncoderDecoder.DecodingException { if (value instanceof JSONNumber) { return ((JSONNumber) value).doubleValue(); } else if (value instanceof JSONBoolean) { return ((JSONBoolean) value).booleanValue(); } else if (value instanceof JSONString) { return ((JSONString) value).stringValue(); } else if (value instanceof JSONArray) { JSONArray array = value.isArray(); List<Object> list = new ArrayList<Object>(array.size()); for (int ct = 0; ct < array.size(); ct++) { list.add(decode(array.get(ct))); } return list; } else if (value instanceof JSONObject) { JSONObject object = value.isObject(); Map<String, Object> map = new HashMap<String, Object>(); for (String key : object.keySet()) { map.put(key, decode(object.get(key))); } return map; } else { return null; } }
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); }
@Override public JSONValue encode(Object value) throws JsonEncoderDecoder.EncodingException { if (value instanceof Number) { return new JSONNumber(((Number) value).doubleValue()); } else if (value instanceof Boolean) { return JSONBoolean.getInstance((Boolean) value); } else if (value instanceof Iterable) { JSONArray array = new JSONArray(); int ct = 0; for (Object v : (Iterable<?>) value) { array.set(ct++, encode(v)); } return array; } else if (value instanceof Map) { JSONObject object = new JSONObject(); for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) { object.put(entry.getKey().toString(), encode(entry.getValue())); } return object; } else if (value == null) { return JSONNull.getInstance(); } else { return new JSONString(value.toString()); } }
public void got(final JSONValue json) { final JSONObject bd = json.isObject(); final JSONString shortrev = bd.get("short_revision").isString(); final JSONString status = bd.get("repo_status").isString(); final JSONNumber stamp = bd.get("timestamp").isNumber(); final JSONString user = bd.get("user").isString(); final JSONString host = bd.get("host").isString(); final JSONString repo = bd.get("repo").isString(); build_data.setHTML( "OpenTSDB built from revision " + shortrev.stringValue() + " in a " + status.stringValue() + " state<br/>" + "Built on " + new Date((long) (stamp.doubleValue() * 1000)) + " by " + user.stringValue() + '@' + host.stringValue() + ':' + repo.stringValue() ); } });
public static FileStructureCommandParametersDto fromJson(JSONValue jsonVal) { if (jsonVal == null) { return null; } JSONObject json= jsonVal.isObject(); FileStructureCommandParametersDto result= new FileStructureCommandParametersDto(); JSONValue jsonshowInheritedJson = json.get("showInherited"); if (jsonshowInheritedJson != null && !(jsonshowInheritedJson.isNull() != null)) { boolean jsonshowInheritedVal = jsonshowInheritedJson.isBoolean().booleanValue(); result.setShowInherited((boolean)jsonshowInheritedVal); } JSONValue jsonuriJson = json.get("uri"); if (jsonuriJson != null && !(jsonuriJson.isNull() != null)) { java.lang.String jsonuriVal = jsonuriJson.isString().stringValue();; result.setUri((java.lang.String)jsonuriVal); } return result; } }
public static void fire(HasDataSelectionEventHandlers source, Object sender, JavaScriptObject data) { DataSelectionEvent event = new DataSelectionEvent(sender); JSONObject array = new JSONObject(data); event.series = new LinkedList<Series>(); for(String key : array.keySet()){ JSONObject obj = array.get(key).isObject(); if(obj != null){ Series series1 = JavaScriptObject.createObject().cast(); series1.setValue(obj.get("value").isNumber().doubleValue()); series1.setColor(obj.get("fillColor").isString().stringValue()); event.series.add(series1); } } source.fireEvent(event); }
public final Map<String, String> getStringStringMap(String key) { if (!hasKey(key)) { return null; } Map<String, String> map = new HashMap<String, String>(); JSONObject object = new JSONObject(this); JSONObject value = (JSONObject) object.get(key); Set<String> keys = value.keySet(); for (String string : keys) { JSONString jValue = value.get(string).isString(); map.put(string, jValue.stringValue()); } return map; }
public static ReImportMavenProjectsCommandParametersDto fromJson(JSONValue jsonVal) { if (jsonVal == null) { return null; } JSONObject json= jsonVal.isObject(); ReImportMavenProjectsCommandParametersDto result= new ReImportMavenProjectsCommandParametersDto(); JSONValue jsonprojectsToUpdateJson = json.get("projectsToUpdate"); if (jsonprojectsToUpdateJson != null && !(jsonprojectsToUpdateJson.isNull() != null)) { ArrayList<java.lang.String> jsonprojectsToUpdateVal= new ArrayList<java.lang.String>(); JSONArray jsonprojectsToUpdateVala = jsonprojectsToUpdateJson.isArray(); for(int jsonprojectsToUpdateValai= 0; jsonprojectsToUpdateValai < jsonprojectsToUpdateVala.size(); jsonprojectsToUpdateValai++) { java.lang.String jsonprojectsToUpdateValaX = jsonprojectsToUpdateVala.get(jsonprojectsToUpdateValai).isString().stringValue();; jsonprojectsToUpdateVal.add(jsonprojectsToUpdateValaX); } result.setProjectsToUpdate((java.util.List<java.lang.String>)jsonprojectsToUpdateVal); } return result; } }
JavaScriptObject asJSO() { final JSONObject parameter = new JSONObject(); if (properties !=null){ for (String key : properties.keySet()) { String value = String.valueOf(properties.get(key)); parameter.put(key, new JSONString(value)); } } return parameter.getJavaScriptObject(); }
/** * Decodes a JSONObject to a map. * * @param jso the JSONObject * @return the map */ public static Map<String, Object> decode(JSONObject jso) { Map<String, Object> map = new FastMap<Object>(); for (String key : jso.keySet()) { JSONValue j = jso.get(key); if (j.isObject() != null) { map.put(key, decode(j.isObject())); } else if (j.isArray() != null) { map.put(key, decodeToList(j.isArray())); } else if (j.isBoolean() != null) { map.put(key, j.isBoolean().booleanValue()); } else if (j.isString() != null) { map.put(key, decodeValue(j.isString().stringValue())); } } return map; }
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 final String toJSONString() { JSONObject object = new JSONObject(); object.put("x", new JSONNumber(getX())); object.put("y", new JSONNumber(getY())); object.put("width", new JSONNumber(getWidth())); object.put("height", new JSONNumber(getHeight())); return object.toString(); }
public final void setStringIntMap(String key, Map<String, Integer> map) { JSONObject object = new JSONObject(); for (String mapKey : map.keySet()) { object.put(mapKey, new JSONNumber(map.get(mapKey))); } set(key, object.getJavaScriptObject()); }