/** Sets the writer where JSON output will be written. This is only necessary when not using the toJson methods. */ public void setWriter (Writer writer) { if (!(writer instanceof JsonWriter)) writer = new JsonWriter(writer); this.writer = (JsonWriter)writer; this.writer.setOutputType(outputType); this.writer.setQuoteLongValues(quoteLongValues); }
/** @param knownType May be null if the type is unknown. */ public void writeObjectStart (String name, Class actualType, Class knownType) { try { writer.name(name); } catch (IOException ex) { throw new SerializationException(ex); } writeObjectStart(actualType, knownType); }
@Override public String serializeState() { StringWriter buffer = new StringWriter(); try { Json json = new Json(); json.setWriter(new JsonWriter(buffer)); json.writeObjectStart(); json.writeValue("level", level); json.writeValue("removeGamma", removeGamma); json.writeObjectEnd(); return buffer.toString(); } finally { StreamUtils.closeQuietly(buffer); } }
/** Writes the specified JSON value, without quoting or escaping. */ public JsonWriter json (String json) throws IOException { requireCommaOrName(); writer.write(json); return this; }
public void close () throws IOException { while (stack.size > 0) pop(); writer.close(); }
public void writeObjectStart () { try { writer.object(); } catch (IOException ex) { throw new SerializationException(ex); } }
public void writeType (Class type) { if (typeName == null) return; String className = getTag(type); if (className == null) className = type.getName(); try { writer.set(typeName, className); } catch (IOException ex) { throw new SerializationException(ex); } if (debug) System.out.println("Writing type: " + type.getName()); }
public void writeArrayStart () { try { writer.array(); } catch (IOException ex) { throw new SerializationException(ex); } }
public void writeObjectStart (String name) { try { writer.name(name); } catch (IOException ex) { throw new SerializationException(ex); } writeObjectStart(); }
@Override public String serializeState() { StringWriter buffer = new StringWriter(); try { Json json = new Json(); json.setWriter(new JsonWriter(buffer)); json.writeObjectStart(); json.writeValue("level", level); json.writeValue("iterations", iterations); json.writeObjectEnd(); return buffer.toString(); } finally { StreamUtils.closeQuietly(buffer); } }
/** Writes the specified JSON value, without quoting or escaping. */ public JsonWriter json (String json) throws IOException { requireCommaOrName(); writer.write(json); return this; }
public void close () throws IOException { while (stack.size > 0) pop(); writer.close(); }
public void writeObjectStart () { try { writer.object(); } catch (IOException ex) { throw new SerializationException(ex); } }
public void writeType (Class type) { if (typeName == null) return; String className = getTag(type); if (className == null) className = type.getName(); try { writer.set(typeName, className); } catch (IOException ex) { throw new SerializationException(ex); } if (debug) System.out.println("Writing type: " + type.getName()); }