AJsonSerHelper { public void writeStringLiteral (String s) throws IOException { if (s == null) { writeNullLiteral (); return; } checkAcceptsValueAndPrefixComma (); _writeStringLiteral (s); afterValueWritten (); } AJsonSerHelper(OutputStream out); void startObject(); void endObject(); void writeKey(String key); void startArray(); void endArray(); void writeStringLiteral(String s); void writeNumberLiteral(long value, int numFracDigits); void writeNumberLiteral(double value, int numFracDigits); void writeBooleanLiteral(boolean value); void writeNullLiteral(); void writeIntLiteral(int value); void writeLongLiteral(long value); void writeStringArray(Iterable<String> values); void writeStringField(String key, String value); void writeBooleanField(String key, Boolean value); void writeIntField(String key, Integer value); void writeLongField(String key, Long value); static String buildString(AStatement1<AJsonSerHelper, E> code); static final Charset UTF_8; }
@Test public void testString() throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final AJsonSerHelper ser = new AJsonSerHelper(baos); ser.writeStringLiteral("abcäöü\r\n\t \\\"{}[]"); final String result = new String(baos.toByteArray(), "utf-8"); assertEquals("\"abcäöü\\u000d\\u000a\\u0009 \\\\\\\"{}[]\"", result); }