### Question:
JsonSerializer { public static void appendString(Appendable buf, CharSequence string) throws IOException { if (string == null || string.length() == 0) { buf.append("\"\""); return; } char current = 0; buf.append('"'); for (int i = 0, j = string.length(); i < j; ++i) { current = string.charAt(i); switch (current) { case '\\': case '"': buf.append('\\'); buf.append(current); break; case '<': buf.append("\\u003c"); break; case '>': buf.append("\\u003e"); break; default: if (current < ' ' || (current >= '\u0080' && current < '\u00a0') || (current >= '\u2000' && current < '\u2100')) { buf.append('\\'); switch (current) { case '\b': buf.append('b'); break; case '\t': buf.append('t'); break; case '\n': buf.append('n'); break; case '\f': buf.append('f'); break; case '\r': buf.append('r'); break; default: buf.append('u'); buf.append(HEX_DIGITS[(current >> 12) & 0xF]); buf.append(HEX_DIGITS[(current >> 8) & 0xF]); buf.append(HEX_DIGITS[(current >> 4) & 0xF]); buf.append(HEX_DIGITS[current & 0xF]); } } else { buf.append(current); } } } buf.append('"'); } private  JsonSerializer(); static String serialize(Object object); static String serialize(JSONObject object); static String serialize(Map<String, ?> map); static String serialize(Collection<?> collection); static String serialize(Object[] array); static String serialize(JSONArray array); @SuppressWarnings("unchecked") static void append(Appendable buf, Object value); static void appendPojo(Appendable buf, Object pojo); static void appendArray(Appendable buf, Object[] array); static void appendJsonArray(Appendable buf, JSONArray array); static void appendCollection(Appendable buf, Collection<?> collection); static void appendMap(final Appendable buf, final Map<String, ?> map); static void appendMultimap(Appendable buf, Multimap<String, Object> map); @SuppressWarnings("unchecked") static void appendJsonObject(Appendable buf, JSONObject object); static void appendString(Appendable buf, CharSequence string);  }### Answer:
@Test public void emptyString() throws Exception { StringBuilder builder = new StringBuilder(); JsonSerializer.appendString(builder, ""); assertEquals("\"\"", builder.toString()); }
@Test public void escapeSequences() throws Exception { StringBuilder builder = new StringBuilder(); JsonSerializer.appendString(builder, "\t\r value \\\foo\b\uFFFF\uBCAD\n\u0083"); assertEquals("\"\\t\\r value \\\\\\foo\\b\uFFFF\uBCAD\\n\\u0083\"", builder.toString()); }
@Test public void escapeBrackets() throws Exception { StringBuilder builder = new StringBuilder(); JsonSerializer.appendString(builder, "Hello<world>foo < bar"); assertEquals("\"Hello\\u003cworld\\u003efoo \\u003c bar\"", builder.toString()); JSONObject obj = new JSONObject("{foo:" + builder + '}'); assertEquals("Hello<world>foo < bar", obj.get("foo")); }