This seems to work.
OutputStream rawStream = ... JsonWriter writer = new JsonWriter(new OutputStreamWriter(rawStream, "UTF-8")); ...
While not "in the API", this should continue to work, given that
- The beginning of the JSON object is a known point (for example, there is no "state" to save after {)
- the completion of an empty JSON object is also a known point ("you can just put a bracket")
- Which, in turn, means that to write a valid JSON as ascii on average, you do not need to affect the state of the JSON record.
Note. I tested this, it works much faster than using JsonWriter.value (String value).
source share