private void writeNumber(Number number) throws IOException {
    String str = number.toString();
    if ("NaN".equals(str) || "Infinity".equals(str) || "-Infinity".equals(str)) {
      throw new IllegalArgumentException(number + " cannot be represented in JSON");
    }
    out.write(str);
  }
Note: The {@link #writeString} and {@link #hex} methods
are based on code from class {@code StringEscapeUtils} in Commons Lang 2.6.
spock-core/src/main/java/org/spockframework/util/JsonWriter.java