Converts this element to a JSON string. <p>For example: <pre> JsonObject object = new JsonObject(); object.add("a", JsonNull.INSTANCE); JsonArray array = new JsonArray(); array.add(1); object.add("b", array); String json = object.toString(); // json: {"a":null,"b":[1]} </pre> If this element or
()
| 418 | * </pre> |
| 419 | */ |
| 420 | @Override |
| 421 | public String toString() { |
| 422 | try { |
| 423 | StringBuilder stringBuilder = new StringBuilder(); |
| 424 | JsonWriter jsonWriter = new JsonWriter(Streams.writerForAppendable(stringBuilder)); |
| 425 | // Make writer lenient because toString() must not fail, even if for example JsonPrimitive |
| 426 | // contains NaN |
| 427 | jsonWriter.setStrictness(Strictness.LENIENT); |
| 428 | Streams.write(this, jsonWriter); |
| 429 | return stringBuilder.toString(); |
| 430 | } catch (IOException e) { |
| 431 | throw new AssertionError(e); |
| 432 | } |
| 433 | } |
| 434 | } |
nothing calls this directly
no test coverage detected