You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by ch...@apache.org on 2026/08/14 04:35:36 UTC
(fory-site) branch main updated: 🔄 synced local 'docs/json/' with remote 'docs/json/'
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 301244a61a 🔄 synced local 'docs/json/' with remote 'docs/json/'
301244a61a is described below
commit 301244a61a9509e54fceb5eac04706f342d664fe
Author: chaokunyang <sh...@gmail.com>
AuthorDate: Fri Aug 14 04:35:31 2026 +0000
🔄 synced local 'docs/json/' with remote 'docs/json/'
---
docs/json/scala.md | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/docs/json/scala.md b/docs/json/scala.md
index 06218c0c43..6cd6e68804 100644
--- a/docs/json/scala.md
+++ b/docs/json/scala.md
@@ -132,23 +132,38 @@ value decodes to `Some(value)`; JSON `null` is rejected for `Some[Int]` but deco
## Scala 2 Enumeration
-Scala 2 erases the owning `Enumeration` from `Enumeration#Value`. Bind the owner explicitly with
-`ScalaEnumerationCodec` and select it through an annotation:
+Scala 2 erases the owning `Enumeration` from `Enumeration#Value`. Use `JsonEnumeration` to retain
+the owner on a direct value, collection or array element, `Option` content, or map key/value:
```scala
+import org.apache.fory.json.scala.JsonEnumeration
+
object Weekday extends Enumeration {
val Monday, Tuesday = Value
}
-final class WeekdayCodec extends ScalaEnumerationCodec(Weekday)
+object Month extends Enumeration {
+ val January, February = Value
+}
case class Schedule(
- @JsonCodec(value = classOf[WeekdayCodec]) day: Weekday.Value,
- @JsonCodec(elementCodec = classOf[WeekdayCodec]) days: List[Weekday.Value]
+ @JsonEnumeration(classOf[Weekday.type]) day: Weekday.Value,
+ @JsonEnumeration(element = classOf[Weekday.type]) days: List[Weekday.Value],
+ @JsonEnumeration(content = classOf[Month.type]) month: Option[Month.Value],
+ @JsonEnumeration(
+ mapKey = classOf[Weekday.type],
+ mapValue = classOf[Month.type]
+ ) labels: Map[Weekday.Value, Month.Value]
)
```
-The codec also implements the map-key contract, so its class can be used in `keyCodec`.
+Each slot describes one direct `Enumeration.Value` occurrence. `value` cannot be combined with a
+child slot, and `element`, `content`, and map slots must match the annotated property's immediate
+type shape. Invalid or conflicting declarations fail when the case-class metadata is created.
+
+For a custom wire representation, extend `ScalaEnumerationCodec` and select the codec through
+`@JsonCodec`. The codec also implements the map-key contract, so its class can be used in
+`keyCodec`.
## Scala 3 closed enums
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org