@Override public JsonWriter value(double value) throws IOException { if (!lenient && (Double.isNaN(value) || Double.isInfinite(value))) { throw new IllegalArgumentException("Numeric values must be finite, but was " + value); } if (promoteValueToName) { return name(Double.toString(value)); } writeDeferredName(); beforeValue(); sink.writeUtf8(Double.toString(value)); pathIndices[stackSize - 1]++; return this; }
@Override public JsonWriter value(boolean value) throws IOException { writeDeferredName(); beforeValue(); sink.writeUtf8(value ? "true" : "false"); pathIndices[stackSize - 1]++; 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(); pushScope(empty); pathIndices[stackSize - 1] = 0; sink.writeUtf8(openBracket); return this; }
@Override public JsonWriter value(long value) throws IOException { if (promoteValueToName) { return name(Long.toString(value)); } writeDeferredName(); beforeValue(); sink.writeUtf8(Long.toString(value)); pathIndices[stackSize - 1]++; return this; }
@Override public JsonWriter nullValue() throws IOException { if (deferredName != null) { if (serializeNulls) { writeDeferredName(); } else { deferredName = null; return this; // skip the name and the value } } beforeValue(); sink.writeUtf8("null"); pathIndices[stackSize - 1]++; return this; }
@Override public JsonWriter value(@Nullable 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); } if (promoteValueToName) { return name(string); } writeDeferredName(); beforeValue(); sink.writeUtf8(string); pathIndices[stackSize - 1]++; return this; }
@Override public JsonWriter value(String value) throws IOException { if (value == null) { return nullValue(); } if (promoteValueToName) { return name(value); } writeDeferredName(); beforeValue(); string(sink, value); pathIndices[stackSize - 1]++; return this; }
@Override public JsonWriter value(double value) throws IOException { if (!lenient && (Double.isNaN(value) || Double.isInfinite(value))) { throw new IllegalArgumentException("Numeric values must be finite, but was " + value); } if (promoteValueToName) { return name(Double.toString(value)); } writeDeferredName(); beforeValue(); sink.writeUtf8(Double.toString(value)); pathIndices[stackSize - 1]++; return this; }
@Override public JsonWriter value(double value) throws IOException { if (!lenient && (Double.isNaN(value) || Double.isInfinite(value))) { throw new IllegalArgumentException("Numeric values must be finite, but was " + value); } if (promoteValueToName) { return name(Double.toString(value)); } writeDeferredName(); beforeValue(); sink.writeUtf8(Double.toString(value)); pathIndices[stackSize - 1]++; return this; }
@Override public JsonWriter value(long value) throws IOException { if (promoteValueToName) { return name(Long.toString(value)); } writeDeferredName(); beforeValue(); sink.writeUtf8(Long.toString(value)); pathIndices[stackSize - 1]++; return this; }
@Override public JsonWriter value(boolean value) throws IOException { writeDeferredName(); beforeValue(); sink.writeUtf8(value ? "true" : "false"); pathIndices[stackSize - 1]++; 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(); pushScope(empty); pathIndices[stackSize - 1] = 0; sink.writeUtf8(openBracket); return this; }
@Override public JsonWriter value(boolean value) throws IOException { writeDeferredName(); beforeValue(); sink.writeUtf8(value ? "true" : "false"); pathIndices[stackSize - 1]++; return this; }
@Override public JsonWriter value(long value) throws IOException { if (promoteValueToName) { return name(Long.toString(value)); } writeDeferredName(); beforeValue(); sink.writeUtf8(Long.toString(value)); pathIndices[stackSize - 1]++; return this; }
@Override public JsonWriter nullValue() throws IOException { if (deferredName != null) { if (serializeNulls) { writeDeferredName(); } else { deferredName = null; return this; // skip the name and the value } } beforeValue(); sink.writeUtf8("null"); pathIndices[stackSize - 1]++; 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(); pushScope(empty); pathIndices[stackSize - 1] = 0; sink.writeUtf8(openBracket); return this; }
@Override public JsonWriter value(@Nullable 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); } if (promoteValueToName) { return name(string); } writeDeferredName(); beforeValue(); sink.writeUtf8(string); pathIndices[stackSize - 1]++; return this; }
@Override public JsonWriter nullValue() throws IOException { if (deferredName != null) { if (serializeNulls) { writeDeferredName(); } else { deferredName = null; return this; // skip the name and the value } } beforeValue(); sink.writeUtf8("null"); pathIndices[stackSize - 1]++; return this; }
@Override public JsonWriter value(String value) throws IOException { if (value == null) { return nullValue(); } if (promoteValueToName) { return name(value); } writeDeferredName(); beforeValue(); string(sink, value); pathIndices[stackSize - 1]++; return this; }
@Override public JsonWriter value(String value) throws IOException { if (value == null) { return nullValue(); } if (promoteValueToName) { return name(value); } writeDeferredName(); beforeValue(); string(sink, value); pathIndices[stackSize - 1]++; return this; }