Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
  /**
   * 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;
  }
Esempio n. 4
0
 /**
  * Encodes {@code value}.
  *
  * @return this writer.
  */
 public JsonWriter value(long value) throws IOException {
   beforeValue(false);
   out.write(Long.toString(value));
   return this;
 }
Esempio n. 5
0
 /**
  * Encodes {@code value}.
  *
  * @return this writer.
  */
 public JsonWriter value(boolean value) throws IOException {
   beforeValue(false);
   out.write(value ? "true" : "false");
   return this;
 }
Esempio n. 6
0
 /**
  * Writes {@code value} literally
  *
  * @return this writer.
  */
 public JsonWriter value(JsonLiteral value) throws IOException {
   beforeValue(false);
   out.write(value.toString());
   return this;
 }
Esempio n. 7
0
 /**
  * Encodes {@code null}.
  *
  * @return this writer.
  */
 public JsonWriter nullValue() throws IOException {
   beforeValue(false);
   out.write("null");
   return this;
 }
Esempio n. 8
0
 /** 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;
 }