uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

Serialize a UniFFI object to JSON from the foreign platform code

Open chris13524 opened this issue 10 months ago • 2 comments

Consumers of my Rust code, in Kotlin and Swift, want to serialize several of our #[uniffi::Record] objects to a JSON string (in order to pass it through yet another layer of FFI). Is this possible currently?

In the docs it looks like UniFFI supports exposing functions from standard Rust crates, however serde::Serialize is not listed here.

I've tried creating a generic helper function to serialize any serializable object. However it looks like #[uniffi::export] doesn't support functions with generic arguments. I could create a separate exported function for each JSON-serializable type, but this would be inconvenient.

For Swift specifically, ideally the generated type implements Encodable.

chris13524 avatar Dec 17 '24 21:12 chris13524