public <A extends Appendable> A toString(A appendable, int indent) throws IOException { return toString(this, appendable, indent); }
public static <A extends Appendable> A toString(Object o, A appendable, int indent) throws IOException { return toString(o, appendable, 0, indent); }
public <A extends Appendable> A toString(A appendable) throws IOException { return toString(this, appendable); }
public <A extends Appendable> A toString(A appendable) throws IOException { return toString(this, appendable); }
public String toString() { try { return toString(new StringBuilder()).toString(); } catch (IOException e) { throw new UndeclaredThrowableException(e); } }
public String toString() { try { return toString(new StringBuilder()).toString(); } catch (IOException e) { throw new UndeclaredThrowableException(e); } }
@Test public void testWriteString() throws Exception { assertEquals("\"a\"", JSON.toString("a", new StringBuilder()).toString()); assertEquals("\"\\\"\"", JSON.toString("\"", new StringBuilder()).toString()); assertEquals("\"\\n\"", JSON.toString("\n", new StringBuilder()).toString()); assertEquals("\"\\r\"", JSON.toString("\r", new StringBuilder()).toString()); assertEquals("\"\\b\"", JSON.toString("\b", new StringBuilder()).toString()); assertEquals("\"\\f\"", JSON.toString("\f", new StringBuilder()).toString()); assertEquals("\"\\t\"", JSON.toString("\t", new StringBuilder()).toString()); }
@Test public void testWriteString() throws Exception { assertEquals("\"a\"", JSON.toString("a", new StringBuilder()).toString()); assertEquals("\"\\\"\"", JSON.toString("\"", new StringBuilder()).toString()); assertEquals("\"\\n\"", JSON.toString("\n", new StringBuilder()).toString()); assertEquals("\"\\r\"", JSON.toString("\r", new StringBuilder()).toString()); assertEquals("\"\\b\"", JSON.toString("\b", new StringBuilder()).toString()); assertEquals("\"\\f\"", JSON.toString("\f", new StringBuilder()).toString()); assertEquals("\"\\t\"", JSON.toString("\t", new StringBuilder()).toString()); }
@Test public void testWriteArray() throws Exception { assertEquals("[0]", JSON.toString(Arrays.asList(0), new StringBuilder()).toString()); }
@Test public void testWriteArray() throws Exception { assertEquals("[0]", JSON.toString(Arrays.asList(0), new StringBuilder()).toString()); }
@Test public void testWriteMap() throws Exception { assertEquals("{\"a\":\"a_value\",\"b\":2}", JSON.toString(new JSON().set("a", "a_value").set("b", 2), new StringBuilder()).toString()); }
@Test public void testWriteMap() throws Exception { assertEquals("{\"a\":\"a_value\",\"b\":2}", JSON.toString(new JSON().set("a", "a_value").set("b", 2), new StringBuilder()).toString()); }
@Test public void testWriteIndented() throws Exception { assertEquals("{\n" + " \"a\":\"a_value\",\n" + " \"b\":2,\n" + " \"c\":[1,2,3],\n" + " \"d\":{\n" + " \"e\":true\n" + " }\n" + "}", JSON.toString(new JSON().set("a", "a_value").set("b", 2).list("c", 1, 2, 3).set("d", new JSON().set("e", true)), new StringBuilder(), 2).toString()); } }
@Test public void testWriteIndented() throws Exception { assertEquals("{\n" + " \"a\":\"a_value\",\n" + " \"b\":2,\n" + " \"c\":[1,2,3],\n" + " \"d\":{\n" + " \"e\":true\n" + " }\n" + "}", JSON.toString(new JSON().set("a", "a_value").set("b", 2).list("c", 1, 2, 3).set("d", new JSON().set("e", true)), new StringBuilder(), 2).toString()); } }
@Test public void testNull() throws Exception { JSON json = new JSON().set("foo", null); String s = json.toString(); assertEquals("{\"foo\":null}", s); JSON unmarshalled = (JSON)JSON.parse(s); assertEquals(json, unmarshalled); }
@Test public void testNull() throws Exception { JSON json = new JSON().set("foo", null); String s = json.toString(); assertEquals("{\"foo\":null}", s); JSON unmarshalled = (JSON)JSON.parse(s); assertEquals(json, unmarshalled); }