fastjson2/docs/design_jsonwriter.md
2022-08-27 03:51:29 +08:00

26 lines
1023 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

JSONWriter是fastjson2序列化的底层实现针对toJSONString和toJSONByte两种场景会使用JSONWriterUTF8和JSONWriterUTF16两种实现。
* JSONWriterUTF16 当使用JSON.toJSONString时缺省使用JSONWriterUTF16。
* JSONWriterUTF8 当使用JSON.toJSONByte时缺省使用JSONWriterUTF8在使用JSON.toJSONString结合JSONWriter.Feature.OptimizedForAscii使用时也会用JSONWriterUTF8实现。
* JSONWriterPretty 当JSONWriter.Feature.PrettyFormat启用时会使用JSONWriterPretty包装一个JSONWriter实现
* JSONWriterJSONB 如果序列化的结果是jsonb格式使用JSONWriterJSONB实现通过相同的API实现两套协议一套API
```java
class JSONWriter { }
class JSONWriterUTF8 extends JSONWriter { }
class JSONWriterUTF16 extends JSONWriter { }
final class JSONWriterPretty extends JSONWriter {
JSONWriter jsonWriter;
JSONWriterPretty(JSONWriter jsonWriter) {
this.jsonWriter = jsonWriter;
}
}
class JSONWriterJSONB extends JSONWriter { }
```