serde-rs / serde

Serialization framework for Rust
https://serde.rs/
Apache License 2.0
9k stars 760 forks source link

Is there a recommended alternative to serde_value? #2780

Open kszlim opened 1 month ago

kszlim commented 1 month ago

I'm trying to build serde's internal representation directly, and there doesn't seem to be a way to do that via serde, thus far, i've been constructing a proxy for that via using serde_json types directly. But I'm wondering if there's a more efficient way?

serde_value looks like what I need, but it also looks unmaintained, perhaps it's a "done" crate? I'm looking for any recommendations.

rushmorem commented 1 month ago

I'm currently working on such an alternative. It addresses a lot of the outstanding issues on serde-value.

kszlim commented 1 month ago

Cool! I notice that everything is boxed unfortunately, is there any potentially workaround to leave "dense" primitive types unboxed (while preserving nullability)?

rushmorem commented 1 month ago

Not everything is boxed. Only structs, enums and non-null options. Those are boxed because the type is self-referential in those variants. The internal Serde type is also structured in a similar way.

is there any potentially workaround to leave "dense" primitive types unboxed (while preserving nullability)?

Well, non-optional values are treated as Some(value) if you deserialise them into an Option so you can avoid a heap allocation by serialising primitive types directly instead of wrapping them in Some where possible.

rushmorem commented 1 month ago

Initial version is now out.