You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Why?
## What does this PR do?
## Related issues
#3732#3736
## AI Contribution Checklist
- [ ] Substantial AI assistance was used in this PR: `yes` / `no`
- [ ] If `yes`, I included a completed [AI Contribution
Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs)
in this PR description and the required `AI Usage Disclosure`.
- [ ] If `yes`, my PR description includes the required `ai_review`
summary and screenshot evidence of the final clean AI review results
from both fresh reviewers on the current PR diff or current HEAD after
the latest code changes.
## Does this PR introduce any user-facing change?
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
@@ -76,6 +77,28 @@ impl ForyDefault for CustomType {
76
77
>
77
78
> **Tip**: If your type supports `#[derive(ForyStruct)]`, you can use `#[fory(generate_default)]` to automatically generate both `ForyDefault` and `Default` implementations.
78
79
80
+
## Manual Serializers and Arc Any
81
+
82
+
If a manually registered serializer needs its type to round-trip behind
83
+
`Arc<dyn Any + Send + Sync>` or preserve `UnknownCase` payloads, implement the
84
+
send-sync Any reader and return the concrete value as a boxed `Any` value:
85
+
86
+
```rust
87
+
implSerializerforCustomType {
88
+
fnfory_read_data_as_send_sync_any(
89
+
context:&mutReadContext,
90
+
) ->Result<Box<dynAny+Send+Sync>, Error> {
91
+
Ok(Box::new(Self::fory_read_data(context)?))
92
+
}
93
+
94
+
// Implement the ordinary Serializer methods as shown above.
95
+
// ...
96
+
}
97
+
```
98
+
99
+
Do not override this method for values that contain fields whose types are not
100
+
`Send + Sync`, such as `Rc<T>`, `RcWeak<T>`, `RefCell<T>`, or `Cell<T>`.
Due to Rust's orphan rule, `Rc<dyn Trait>` and `Arc<dyn Trait>` cannot implement `Serializer` directly. For standalone serialization (not inside struct fields), the `register_trait_type!` macro generates wrapper types.
182
222
183
-
**Note:** If you don't want to use wrapper types, you can serialize as `Rc<dyn Any>` or `Arc<dyn Any + Send + Sync>` instead (see the dyn Any section above).
223
+
**Note:** If you don't want to use wrapper types for concrete non-container payloads, you can serialize as `Box<dyn Any>`, `Rc<dyn Any>`, or `Arc<dyn Any + Send + Sync>` instead (see the dyn Any section above).
184
224
185
225
The `register_trait_type!` macro generates `AnimalRc` and `AnimalArc` wrapper types:
0 commit comments