How to implement a Serde wrapper for a data format that is richer than Serde's data model?

Hello everyone! I am looking to implement a Serde wrapper for a data format like Transit.

Transit is a self-descriptive format which is richer than Serde's own data model, in that it has first-class support for bigints, decimals, UUIDs, timestamps and sets.

It would be really nice to work as part of the Serde ecosystem, but I'm having trouble figuring out how to customize the way timestamps, bigints, sets etc. are (de)serialized.
Their implementations of Serialize seem to always turn e.g. timestamps into strings and sets into sequences, seemingly without having any way to customize this for individual formats.

Are there ways to have Serde work well with richer data formats?
Or is this a fool's errand and is the only way forward to provide a separate set of traits and derive macros which are almost-but-not-quite identical to Serde's?

1 Like

The common approach to this is to define "magic" types in the crate which are special-cased by the serializer and deserializer implementations.

See for example the handling of BigInteger in serde-smile:


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.