/** Utility method to print out the contents of a json object. */ protected void print(JSON json) { System.out.println(json.toString(2)); }
@Override protected void write(Object object, OutputStream out) throws IOException { //TODO: character set Writer outWriter = new BufferedWriter(new OutputStreamWriter(out)); //JD: why does this initial flush occur? outWriter.flush(); JSON obj = (JSON)toJSONObject(object); obj.write(outWriter); outWriter.flush(); }
@Override protected Void run() throws Exception { if (step.getJson() == null) { throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingJSON(step.getDescriptor().getFunctionName())); } if (StringUtils.isBlank(step.getFile())) { throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingFile(step.getDescriptor().getFunctionName())); } if (isNotBlank(step.getFile()) && ws == null) { // Need a workspace if we are writing to a file. throw new MissingContextVariableException(FilePath.class); } FilePath path = ws.child(step.getFile()); if (path.isDirectory()) { throw new FileNotFoundException(Messages.JSONStepExecution_fileIsDirectory(path.getRemote())); } try (OutputStreamWriter writer = new OutputStreamWriter(path.write())) { if (step.getPretty() > 0) { writer.write(step.getJson().toString(step.getPretty())); } else { step.getJson().write(writer); } } return null; }
public static CreateRequest createRequest(AdminClient adminClient, TypeClient typeClient, ActionCreate actionCreate, OA2Client client, JSON json) { if (json.isArray()) { throw new IllegalArgumentException("Error: cannot create a client from a JSON array -- it must be an map (JSON object) of key/value pairs"); } return new CreateRequest(adminClient, client, (JSONObject) json); }
@Override public void writeInternal(Map<?, ?> map, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { // TODO: character set Writer outWriter = new BufferedWriter(new OutputStreamWriter(outputMessage.getBody())); // JD: why does this initial flush occur? outWriter.flush(); JSON obj = (JSON) toJSONObject(map); obj.write(outWriter); outWriter.flush(); }
@Override protected Void run() throws Exception { FilePath ws = getContext().get(FilePath.class); assert ws != null; if (step.getJson() == null) { throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingJSON(step.getDescriptor().getFunctionName())); } if (StringUtils.isBlank(step.getFile())) { throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingFile(step.getDescriptor().getFunctionName())); } FilePath path = ws.child(step.getFile()); if (path.isDirectory()) { throw new FileNotFoundException(Messages.JSONStepExecution_fileIsDirectory(path.getRemote())); } try (OutputStreamWriter writer = new OutputStreamWriter(path.write(), "UTF-8")) { if (step.getPretty() > 0) { writer.write(step.getJson().toString(step.getPretty())); } else { step.getJson().write(writer); } } return null; }
protected static JSONObject wrapArray(final JSON json) { if (json.isArray()) { final JSONObject wrapper = new JSONObject(); wrapper.put("elements", json); return wrapper; } else { return (JSONObject) json; } } }
/** Utility method to print out the contents of a json object. */ protected void print(JSON json) { if (isQuietTests()) { return; } System.out.println(json.toString(2)); }
protected void writeJSON(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { JSON json = createJSON(model, request, response); json = (JSON) (((JSONObject) json).get(modelItemKey)); json.write(response.getWriter()); }
public UUID getUUIDName(String name){ BiMap<String, UUID>invmap= names.inverse(); UUID u = null; if(invmap.containsKey(name)){ u = invmap.get(name); }else{ String result = c.sendGetRequest("https://api.mojang.com/users/profiles/minecraft/" + name); JSON jsonr = JSONSerializer.toJSON(result); if(!jsonr.isArray()){ JSONObject js = (JSONObject) jsonr; u = new UUID(new BigInteger(js.getString("id").substring(0, 16), 16).longValue(),new BigInteger(js.getString("id").substring(16), 16).longValue()); names.put(u, name); } } return u; }
/** * Helper method: prints out a JSON object * * @param o the JSON Object */ public static void printJson(JSON o) { l.info(o.toString(2)); }
protected boolean handleJSON(StaplerResponse rsp, Object response) throws IOException { if (response instanceof JSON) { rsp.setContentType(Flavor.JSON.contentType); ((JSON)response).write(rsp.getWriter()); return true; } return false; } }
public static AttributeSetClientRequest createRequest(AdminClient aSubj, TypeAttribute typeAttribute, ActionSet actionSet, OA2Client cTarget, JSON content) { if (content.isArray()) { throw new GeneralException("Content must be a map of attributes to set"); } return new AttributeSetClientRequest(aSubj, cTarget, (JSONObject) content); }
private String formatJSON(String json) { JSON object = JSONSerializer.toJSON(json, config); return object.toString(4); // TODO: make a property to manage the indent }
protected boolean handleJSON(StaplerResponse rsp, Object response) throws IOException { if (response instanceof JSON) { rsp.setContentType(Flavor.JSON.contentType); ((JSON)response).write(rsp.getWriter()); return true; } return false; } }
protected static JSONObject wrapArray(final JSON json) { if (json.isArray()) { final JSONObject wrapper = new JSONObject(); wrapper.put("elements", json); return wrapper; } else { return (JSONObject) json; } } }
net.sf.json.xml.XMLSerializer xmlSerializer = new net.sf.json.xml.XMLSerializer(); JSON json = xmlSerializer.read( xmlString ); System.out.println( json.toString(2) );
protected boolean handleJSON(StaplerResponse rsp, Object response) throws IOException { if (response instanceof JSON) { rsp.setContentType(Flavor.JSON.contentType); ((JSON)response).write(rsp.getWriter()); return true; } return false; } }
/** * Populate a fixed-length list from JSON data objects. * * @param sourceJson * A {@link JSON} object representing an array of JSON data objects or a single JSON data object from * which data will be pulled. * @param field * A {@link Field} object representing the fixed-length list to be populated. * @param recordList * A {@link RecordList} containing records into which values will be populated. */ private static void putFixedListFromJson(final JSON sourceJson, final Field field, final RecordList recordList) { if (sourceJson.isArray()) putFixedListDeepFromJson((JSONArray) sourceJson, field, recordList); else putFixedListShallowFromJson((JSONObject) sourceJson, field, recordList); }