The idea is to go through a proxy type OptionFlatMapDeserializer when calling deserialize_option in FlatMapDeserializer. Such proxy type provides a custom error type FlatStructError which only catches missing_field error during the immediate struct deserialization. All the errors happening nested will be preserved in another variant. In this way, we could propagate error inside a flattened struct.
I guess some more tests and comments are needed, but I want to put this work forward for preliminary test.
This is an attempt to address https://github.com/serde-rs/json/issues/644
The idea is to go through a proxy type
OptionFlatMapDeserializer
when callingdeserialize_option
inFlatMapDeserializer
. Such proxy type provides a custom error typeFlatStructError
which only catchesmissing_field
error during the immediate struct deserialization. All the errors happening nested will be preserved in another variant. In this way, we could propagate error inside a flattened struct.I guess some more tests and comments are needed, but I want to put this work forward for preliminary test.