Marcono1234 / struson

Streaming JSON reader and writer written in Rust
https://crates.io/crates/struson
Apache License 2.0
59 stars 6 forks source link

Serialization does not work with `serde_with::skip_serializing_none` #41

Closed IgnisDa closed 7 months ago

IgnisDa commented 7 months ago

This was the reason #40 happened for me. Removing #[skip_serializing_none] from my struct gets everything working again.

Ref: https://docs.rs/serde_with/3.1.0/serde_with/attr.skip_serializing_none.html

IgnisDa commented 7 months ago

It would be great if skip_serializing_none is supported since otherwise there are a lot of nulls in the export performed.

Marcono1234 commented 7 months ago

Thanks for the report! I was able to reproduce this locally. The Serializer implementation in Struson validates the provided len to methods such as serialize_struct, but it seems I got the handling in skip_field incorrect, leading to the error you are seeing. I will fix that in that next days.

However, I am also considering removing validation of the len (see #42) since Serde JSON's implementation does not validate it either.

IgnisDa commented 7 months ago

Thanks for taking a look!

However, I am also considering removing validation of the len (see https://github.com/Marcono1234/struson/issues/42) since Serde JSON's implementation does not validate it either.

In my case, since the JSON is already validated, the struson validation is not required. But maybe you are aware of use-cases where it might be required. Either way, it is fine if you remove the validation for my use-case.

Marcono1234 commented 7 months ago

This should be fixed in version 0.4.1, please let me know if you encounter any other issues.

And thanks for considering to use Struson!

IgnisDa commented 7 months ago

Works perfectly now, thanks!