This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory-site.git
The following commit(s) were added to refs/heads/main by this push:
new 0798e94ce3 🔄 synced local 'docs/guide/' with remote 'docs/guide/'
0798e94ce3 is described below
commit 0798e94ce3935640288b3cbf6336dc7dd8c6be32
Author: chaokunyang <[email protected]>
AuthorDate: Thu Jul 16 12:35:35 2026 +0000
🔄 synced local 'docs/guide/' with remote 'docs/guide/'
---
docs/guide/java/json-support.md | 41 ++++++++++++-----------------------------
1 file changed, 12 insertions(+), 29 deletions(-)
diff --git a/docs/guide/java/json-support.md b/docs/guide/java/json-support.md
index 6d3dbfe447..de53319132 100644
--- a/docs/guide/java/json-support.md
+++ b/docs/guide/java/json-support.md
@@ -895,29 +895,18 @@ concrete String/UTF-8 writers and Latin-1/UTF-16/UTF-8
readers. It is a direct s
not a JSON abstract syntax tree (AST) codec. It never handles Map keys;
`MapKeyCodec` owns JSON
object member names.
-Implement all five representations with the same JSON shape:
+For an application codec with the same semantics in every representation,
extend
+`AbstractJsonValueCodec<T>` and implement the JSON shape once:
```java
import java.math.BigDecimal;
-import org.apache.fory.json.codec.JsonValueCodec;
-import org.apache.fory.json.reader.Latin1JsonReader;
-import org.apache.fory.json.reader.Utf16JsonReader;
-import org.apache.fory.json.reader.Utf8JsonReader;
-import org.apache.fory.json.writer.StringJsonWriter;
-import org.apache.fory.json.writer.Utf8JsonWriter;
-
-public final class MoneyCodec implements JsonValueCodec<Money> {
- @Override
- public void writeString(StringJsonWriter writer, Money value) {
- if (value == null) {
- writer.writeNull();
- } else {
- writer.writeBigDecimal(value.amount);
- }
- }
+import org.apache.fory.json.codec.AbstractJsonValueCodec;
+import org.apache.fory.json.reader.JsonReader;
+import org.apache.fory.json.writer.JsonWriter;
+public final class MoneyCodec extends AbstractJsonValueCodec<Money> {
@Override
- public void writeUtf8(Utf8JsonWriter writer, Money value) {
+ public void write(JsonWriter writer, Money value) {
if (value == null) {
writer.writeNull();
} else {
@@ -926,17 +915,7 @@ public final class MoneyCodec implements
JsonValueCodec<Money> {
}
@Override
- public Money readLatin1(Latin1JsonReader reader) {
- return reader.tryReadNullToken() ? null : new
Money(reader.readBigDecimal());
- }
-
- @Override
- public Money readUtf16(Utf16JsonReader reader) {
- return reader.tryReadNullToken() ? null : new
Money(reader.readBigDecimal());
- }
-
- @Override
- public Money readUtf8(Utf8JsonReader reader) {
+ public Money read(JsonReader reader) {
return reader.tryReadNullToken() ? null : new
Money(reader.readBigDecimal());
}
}
@@ -950,6 +929,10 @@ final class Money {
}
```
+`AbstractJsonValueCodec` adds one virtual method call per operation. For a
+performance-sensitive codec, or when behavior depends on a concrete reader or
writer, implement
+`JsonValueCodec<T>` directly and provide all five representation-specific
methods.
+
Register it once:
```java
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]