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

[serde-ser] Remove validation of expected length #42

Open Marcono1234 opened 7 months ago

Marcono1234 commented 7 months ago

Problem solved by the enhancement

Multiple Serde Serializer methods take a len argument, for example Serializer::serialize_seq. Serde JSON does not seem to actually validate this argument, it just checks it to special-case empty containers, see e.g. serialize_seq for writing to Write or serialize_seq for creating a Value.

Struson currently validates the length and returns a SerializerError::IncorrectElementsCount on mismatch. The intention was to help users detect incorrect handwritten Serialize implementations. However, this validation causes the following issues:

Enhancement description

Remove the validation of the expected length, and remove SerializerError::IncorrectElementsCount

Alternatives / workarounds

Fix the bugs in the current length checks, and verify that it behaves correctly for derived Serialize

Marcono1234 commented 7 months ago

Have implemented this experimentally in the serde-ser-remove-length-validation branch, however for now I will not merge this since the validation helps with detecting bad Serialize implementations (assuming the validation is correct).

In case the validation turns out to be incorrect or too strict, I might consider merging this in the future.