Refine search
@Override public DataPointWriter startDataPointSet(String type, SortedMap<String, String> tags) throws IOException { m_lock.writeLock().lock(); try { m_jsonWriter = new JSONWriter(m_writer); m_jsonWriter.object(); m_jsonWriter.key("name").value(m_metric); m_jsonWriter.key("tags").value(tags); m_jsonWriter.key("datapoints").array(); } catch (JSONException e) { throw new IOException(e); } return new ExportDataPointWriter(); }
/** * Begin appending a new object. All keys and values until the balancing * <code>endObject</code> will be appended to this object. The * <code>endObject</code> method must be called to mark the object's end. * @return this * @throws JSONException If the nesting is too deep, or if the object is * started in the wrong place (for example as a key or after the end of the * outermost array or object). */ public JSONWriter object() throws JSONException { if (this.mode == 'i') { this.mode = 'o'; } if (this.mode == 'o' || this.mode == 'a') { this.append("{"); this.push(new JSONObject()); this.comma = false; return this; } throw new JSONException("Misplaced object."); }
@Override public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) { try { JSONStringer jsonStr = new JSONStringer(); JSONWriter writer = jsonStr.object(); writer.key("worksheetId").value(worksheetId); writer.key("updateType").value("AddLiteralNodeUpdate"); writer.key("hNodeId").value(nodeId); writer.key("uri").value(literalValue); writer.endObject(); pw.print(writer.toString()); } catch (JSONException e) { logger.error("Error occured while writing to JSON!", e); } }
/** * Begin appending a new array. All values until the balancing * <code>endArray</code> will be appended to this array. The * <code>endArray</code> method must be called to mark the array's end. * @return this * @throws JSONException If the nesting is too deep, or if the object is * started in the wrong place (for example as a key or after the end of the * outermost array or object). */ public JSONWriter array() throws JSONException { if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') { this.push(null); this.append("["); this.comma = false; return this; } throw new JSONException("Misplaced array."); }
public static void annotationToJson(JSONStringer js, Annotation ann) { js.object(); Class<? extends Annotation> annotationType = ann.annotationType(); js.key("type").value(annotationType.getName()); js.key("properties").object(); for (Method method : annotationType.getDeclaredMethods()) { try { Object propertyValue = method.invoke(ann); js.key(method.getName()); annotationPropertyValueAsJson(js, propertyValue); } catch (Exception e) { logger.warn("Exception reading annotation property, skipping", e); } } js.endObject(); js.endObject(); }
public static String buildJSON(Map<String, Object> params) { final JSONStringer stringer = new JSONStringer(); stringer.object(); for (Map.Entry<String, Object> param : params.entrySet()) { if (param.getKey() != null && !"".equals(param.getKey()) && param.getValue() != null && !"" .equals(param.getValue())) { stringer.key(param.getKey()).value(param.getValue()); } } return stringer.endObject().toString(); }
public static void // modifies json_out toJson(Object object, JSONStringer json_out) throws Exception { json_out.object(); json_out.key(f.getName()); ((JsonAble) value).toJson(json_out); json_out.key(f.getName()); json_out.array(); for (Object e : (ArrayList) value) { json_out.key(f.getName()).value(value);
@Override public void writeValueToJson(JSONWriter writer) throws JSONException { writer.value(m_value); }
/** * Append an object value. * @param o The object to append. It can be null, or a Boolean, Number, * String, JSONObject, or JSONArray, or an object with a toJSONString() * method. * @return this * @throws JSONException If the value is out of sequence. */ public JSONWriter value(Object o) throws JSONException { return this.append(JSONObject.valueToString(o)); } }
/** * End an array. This method most be called to balance calls to * <code>array</code>. * @return this * @throws JSONException If incorrectly nested. */ public JSONWriter endArray() throws JSONException { return this.end('a', ']'); }
/** * Append either the value <code>true</code> or the value * <code>false</code>. * @param b A boolean. * @return this * @throws JSONException */ public JSONWriter value(boolean b) throws JSONException { return this.append(b ? "true" : "false"); }
public JsonResponse(Writer writer) { m_writer = writer; m_jsonWriter = new JSONWriter(writer); }
/** * Append an object value. * @param object The object to append. It can be null, or a Boolean, Number, * String, JSONObject, or JSONArray, or an object that implements JSONString. * @return this * @throws JSONException If the value is out of sequence. */ public JSONWriter value(Object object) throws JSONException { return this.append(valueToString(object)); } }