code: private static void serializeString(StringBuilder builder, String str) {
      builder.append('"');
      int last = 0;
      int length = str.length();
      for (int i = 0; i < length; i++) {
        char c = str.charAt(i);
        String replacement;
        if (c < 128) {
          replacement = REPLACEMENT_CHARS[c];
          if (replacement == null) {
            continue;
          }
        } else if (c == '\u2028') {
          replacement = "\\u2028";
        } else if (c == '\u2029') {
          replacement = "\\u2029";
        } else {
          continue;
        }
        if (last < i) {
          builder.append(str, last, i);
        }
        builder.append(replacement);
        last = i + 1;
      }
      if (last < length) {
        builder.append(str, last, length);
      }
      builder.append('"');
    }
docs: https://github.com/google/gson/blob/59edfc1caf2bb30e30f523f8502f23e8f8edc38e/gson/src/main/java/com/google/gson/stream/JsonWriter.java