@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; }
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(); 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 void onSuccess( JavaScriptObject result ) { JSONArray params = new JSONArray(); params.set( 0, new JSONNumber( hangOutId ) ); params.set( 1, new JSONObject( result ) ); req.request = new RequestDesc( req.request.service, req.request.interfaceChecksum, "_hang_out_reply_", params ); sendRequest( req.request, req.cookie, req.callback ); } } );
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; }
/** * Parse the given JSON string into a {@link JSONObject}. * * @param jsonString The trusted JSON string to parse. * @return The JSON object that results from the parsed string. * @throws JSONException Thrown in case something went wrong during parsing. */ public static JSONValue parse(String jsonString) throws JSONException { if (jsonString == null || "".equals(jsonString)) { return JSONNull.getInstance(); } if (jsonString.charAt(0) == '[') { return new JSONArray(eval(jsonString)); } return new JSONObject(eval(jsonString)); }
@Override public JSONValue serialize(final Map<K, V> map) { if (map == null) { return JSONNull.getInstance(); } final JSONObject jsonObject = new JSONObject(); for (K key : map.keySet()) { GWTPojoSerializerUtils.setProperty(jsonObject, key.toString(), vSerializer.serialize(map.get(key))); } return jsonObject; }
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 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 void onSuccess( JavaScriptObject result ) { JSONArray params = new JSONArray(); params.set( 0, new JSONNumber( hangOutId ) ); params.set( 1, new JSONObject( result ) ); req.request = new RequestDesc( req.request.service, req.request.interfaceChecksum, "_hang_out_reply_", params ); sendRequest( req.request, req.cookie, req.callback ); } } );
public static JSONValue And( List<JSONValue> operands ) { JSONObject obj = new JSONObject(); obj.put( "op", new JSONString( "and" ) ); JSONArray ops = new JSONArray(); int i = 0; for( JSONValue op : operands ) ops.set( i++, op ); obj.put( "ops", ops ); return obj; }
public JSONValue toJsonElement() { JSONObject result = new JSONObject(); if (getPreferences() == null) { setPreferences((java.util.Map<java.lang.String, java.lang.String>)null); } else { JSONObject preferencesVal = new JSONObject(); for (Entry<String, java.lang.String> preferencesValX : getPreferences().entrySet()) { JSONValue preferencesValY = preferencesValX.getValue() == null ? JSONNull.getInstance() : new JSONString(preferencesValX.getValue());; preferencesVal.put(preferencesValX.getKey().toString(), preferencesValY); } result.put("preferences", preferencesVal); } 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()); }
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; }