@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 stackTraceElementAsJsonObject( StackTraceElement e) { JSONObject obj = new JSONObject(); if (e != null) { obj.put("className", getJsonString(e.getClassName())); obj.put("fileName", getJsonString(e.getFileName())); obj.put("methodName", getJsonString(e.getMethodName())); obj.put("lineNumber", getJsonString("" + e.getLineNumber())); } return obj; }
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; }
public void testReadListFromJSONObjectWithNonExistingArrayKey() { JSONObject json = new JSONObject(); json.put("foo", new JSONArray()); List<Amoeba> amoebas = Amoeba.JSON_READER.readList(json, "bar"); assertNull(amoebas); }
@Override public JSONObject toJSONObject() { final JSONObject object = super.toJSONObject(); final NFastArrayList<PathPartList> list = getPathPartListArray(); final JSONArray path = new JSONArray(); final int size = list.size(); for (int i = 0; i < size; i++) { path.set(i, list.get(i).toJSONArray()); } object.put("path-list", path); return object; }
public JSON appendNull(final String propName) { object.put(propName, JSONNull.getInstance()); return this; }
public JSONValue toJsonElement() { JSONObject result = new JSONObject(); if (getRefactoringStatus() == null) { setRefactoringStatus((org.eclipse.che.jdt.ls.extension.api.dto.RefactoringStatus)null); } else { JSONValue refactoringStatusVal = getRefactoringStatus() == null ? JSONNull.getInstance() : ((RefactoringStatusDto)getRefactoringStatus()).toJsonElement();; result.put("refactoringStatus", refactoringStatusVal); } if (getCheWorkspaceEdit() == null) { setCheWorkspaceEdit((org.eclipse.che.jdt.ls.extension.api.dto.CheWorkspaceEdit)null); } else { JSONValue cheWorkspaceEditVal = getCheWorkspaceEdit() == null ? JSONNull.getInstance() : ((CheWorkspaceEditDto)getCheWorkspaceEdit()).toJsonElement();; result.put("cheWorkspaceEdit", cheWorkspaceEditVal); } return result; }
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; } }
public JSONObject toJsonObjectInt(boolean copyJsons) { JSONObject result = new JSONObject(); JSONValue stateOut = (this.state == null) ? JSONNull.getInstance() : new JSONString(this.state.name()); result.put("state", stateOut); JSONValue outputOut = (this.output == null) ? JSONNull.getInstance() : new JSONString(this.output); result.put("output", outputOut); return result; }
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 void testReadListFromJSONObjectWithEmptyArrayWithArrayKey() { JSONObject json = new JSONObject(); json.put("foo", new JSONArray()); List<Amoeba> amoebas = Amoeba.JSON_READER.readList(json, "foo"); assertNotNull(amoebas); assertTrue(amoebas.isEmpty()); }
@Override public JSONObject toJSONObject() { final JSONObject object = super.toJSONObject(); final NFastArrayList<PathPartList> list = getPathPartListArray(); final JSONArray path = new JSONArray(); final int size = list.size(); for (int i = 0; i < size; i++) { path.set(i, list.get(i).toJSONArray()); } object.put("path-list", path); return object; }
public JSON appendNull(final String propName) { object.put(propName, JSONNull.getInstance()); return this; }
public static JSONValue And( JSONValue... operands ) { JSONObject obj = new JSONObject(); obj.put( "op", new JSONString( "and" ) ); JSONArray ops = new JSONArray(); for( int i = 0; i < operands.length; i++ ) ops.set( i, operands[i] ); obj.put( "ops", ops ); return obj; }
public JSONObject toJsonObjectInt(boolean copyJsons) { JSONObject result = new JSONObject(); JSONValue versionOut = (this.version == null) ? JSONNull.getInstance() : new JSONString(this.version); result.put("version", versionOut); JSONValue repositoryOut = (this.repository == null) ? JSONNull.getInstance() : new JSONString(this.repository); result.put("repository", repositoryOut); JSONObject propertiesOut = new JSONObject(); this.ensureProperties(); for (java.util.Map.Entry<String, java.lang.String> entry0 : this.properties.entrySet()) { java.lang.String properties_ = entry0.getValue(); JSONValue propertiesOut_ = (properties_ == null) ? JSONNull.getInstance() : new JSONString(properties_); propertiesOut.put(entry0.getKey(), propertiesOut_); } result.put("properties", propertiesOut); JSONValue artifactIdOut = (this.artifactId == null) ? JSONNull.getInstance() : new JSONString(this.artifactId); result.put("artifactId", artifactIdOut); JSONValue groupIdOut = (this.groupId == null) ? JSONNull.getInstance() : new JSONString(this.groupId); result.put("groupId", groupIdOut); return result; }
public static JSONObject wrapJson( JSONValue json ) { JSONObject obj = new JSONObject(); obj.put( "v", new JSONString( "v2" ) ); obj.put( "data", json ); return obj; }
public void testReadListFromJSONObjectWithEmptyArray() { JSONObject json = new JSONObject(); json.put("foo", new JSONArray()); List<Amoeba> amoebas = Amoeba.JSON_READER.readList(json); assertNotNull(amoebas); assertTrue(amoebas.isEmpty()); }
@Override public JSONObject toJSONObject() { final JSONObject object = super.toJSONObject(); final NFastArrayList<PathPartList> list = getPathPartListArray(); final JSONArray path = new JSONArray(); final int size = list.size(); for (int i = 0; i < size; i++) { path.set(i, list.get(i).toJSONArray()); } object.put("path-list", path); return object; }
protected static boolean isNotNullAndCheckDefaults(Object object, JSONObject value, String jsonName) { if (object != null) { return true; } else if (Defaults.doesIgnoreJsonNulls()) { return false; } else { value.put(jsonName, JSONNull.getInstance()); return false; } }