/** * 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 { if (Double.isNaN(value) || Double.isInfinite(value)) { throw new IllegalArgumentException("Numeric values must be finite, but was " + value); } beforeValue(false); out.append(Double.toString(value)); 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(); } beforeValue(false); string(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(); } 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(false); out.append(string); return this; }
/** * Encodes {@code value}. * * @return this writer. */ public JsonWriter value(long value) throws IOException { beforeValue(false); out.write(Long.toString(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; }
/** * Writes {@code value} literally * * @return this writer. */ public JsonWriter value(JsonLiteral value) throws IOException { beforeValue(false); out.write(value.toString()); return this; }
/** * Encodes {@code null}. * * @return this writer. */ public JsonWriter nullValue() throws IOException { beforeValue(false); out.write("null"); 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; }