/** * Enters a new scope by appending any necessary whitespace and the given * bracket. */ private JsonWriter open(int empty, String openBracket) throws IOException { beforeValue(); push(empty); out.write(openBracket); return this; }
/** * Encodes {@code value}. * * @return this writer. */ public JsonWriter value(boolean value) throws IOException { writeDeferredName(); beforeValue(); out.write(value ? "true" : "false"); return this; }
/** * Encodes {@code value}. * * @return this writer. */ public JsonWriter value(long value) throws IOException { writeDeferredName(); beforeValue(); out.write(Long.toString(value)); return this; }
/** * Encodes {@code value}. * * @return this writer. */ public JsonWriter value(Boolean value) throws IOException { if (value == null) { return nullValue(); } writeDeferredName(); beforeValue(); out.write(value ? "true" : "false"); return this; }
/** * Writes {@code value} directly to the writer without quoting or * escaping. * * @param value the literal string value, or null to encode a null literal. * @return this writer. */ public JsonWriter jsonValue(String value) throws IOException { if (value == null) { return nullValue(); } writeDeferredName(); beforeValue(); out.append(value); return this; }
/** * Encodes {@code null}. * * @return this writer. */ public JsonWriter nullValue() throws IOException { if (deferredName != null) { if (serializeNulls) { writeDeferredName(); } else { deferredName = null; return this; // skip the name and the value } } beforeValue(); out.write("null"); return this; }
/** * Encodes {@code value}. * * @param value a finite value. May not be {@link Double#isNaN() NaNs} or * {@link Double#isInfinite() infinities}. * @return this writer. */ public JsonWriter value(double value) throws IOException { writeDeferredName(); if (!lenient && (Double.isNaN(value) || Double.isInfinite(value))) { throw new IllegalArgumentException("Numeric values must be finite, but was " + value); } beforeValue(); out.append(Double.toString(value)); return this; }
/** * Encodes {@code value}. * * @param value a finite value. May not be {@link Double#isNaN() NaNs} or * {@link Double#isInfinite() infinities}. * @return this writer. */ public JsonWriter value(Number value) throws IOException { if (value == null) { return nullValue(); } writeDeferredName(); String string = value.toString(); if (!lenient && (string.equals("-Infinity") || string.equals("Infinity") || string.equals("NaN"))) { throw new IllegalArgumentException("Numeric values must be finite, but was " + value); } beforeValue(); out.append(string); return this; }
/** * Encodes {@code value}. * * @param value the literal string value, or null to encode a null literal. * @return this writer. */ public JsonWriter value(String value) throws IOException { if (value == null) { return nullValue(); } writeDeferredName(); beforeValue(); string(value); return this; }
/** * Encodes {@code value}. * * @return this writer. */ public JsonWriter value(boolean value) throws IOException { beforeValue(false); out.write(value ? "true" : "false"); return this; }
/** * Enters a new scope by appending any necessary whitespace and the given * bracket. */ private JsonWriter open(JsonScope empty, String openBracket) throws IOException { beforeValue(true); stack.add(empty); out.write(openBracket); return this; }
/** * Enters a new scope by appending any necessary whitespace and the given * bracket. */ private JsonWriter open(int empty, String openBracket) throws IOException { beforeValue(true); push(empty); out.write(openBracket); return this; }
/** * Encodes {@code value}. * * @return this writer. */ public JsonWriter value(boolean value) throws IOException { writeDeferredName(); beforeValue(false); out.write(value ? "true" : "false"); return this; }
/** * Encodes {@code value}. * * @return this writer. */ public JsonWriter value(long value) throws IOException { writeDeferredName(); beforeValue(false); out.write(Long.toString(value)); return this; }
/** * Encodes {@code value}. * * @return this writer. */ public JsonWriter value(long value) throws IOException { writeDeferredName(); beforeValue(false); out.write(Long.toString(value)); return this; }
/** * Enters a new scope by appending any necessary whitespace and the given * bracket. */ private JsonWriter open(int empty, String openBracket) throws IOException { beforeValue(); push(empty); out.write(openBracket); return this; }
/** * Encodes {@code value}. * * @return this writer. */ public JsonWriter value(boolean value) throws IOException { writeDeferredName(); beforeValue(false); out.write(value ? "true" : "false"); return this; }
/** * Enters a new scope by appending any necessary whitespace and the given * bracket. */ private JsonWriter open(int empty, String openBracket) throws IOException { beforeValue(true); push(empty); out.write(openBracket); return this; }
/** * Encodes {@code value}. * * @return this writer. */ public JsonWriter value(boolean value) throws IOException { writeDeferredName(); beforeValue(false); out.write(value ? "true" : "false"); return this; }
/** * Encodes {@code value}. * * @return this writer. */ public JsonWriter value(long value) throws IOException { writeDeferredName(); beforeValue(false); out.write(Long.toString(value)); return this; }