serde icon indicating copy to clipboard operation
serde copied to clipboard

Support flattened externally tagged enums with default attributes

Open andrewtoth opened this issue 1 year ago • 4 comments

This adds a custom error type for FlatMapDeserializer, which distinguishes the specific no variant of enum {name} found in flattened data error.

This error is then used in deserialize_map in serde_derive to match on the returned error, and if the field or container has a default attribute it uses the expr_is_missing to provide a default value.

Fixes https://github.com/serde-rs/serde/issues/1626

andrewtoth avatar Feb 02 '24 05:02 andrewtoth

The tests fail due to trybuild using an older version of serde or serde_derive. This PR only modifies API in the private mod, and in serde_derive. However, if after this patch both serde and serde_derive are not upgraded in lockstep then this will break at compile time. I'm not completely sure then, if this can be considered a non-breaking change? If all packages using serde and serde_derive in a project upgrade in lockstep then there is no external breaking change. Is it a requirement that serde_derive and serde be backwards compatible with older versions of each other?

andrewtoth avatar Feb 02 '24 22:02 andrewtoth

@Mingun thank you for your review and suggestions! I implemented them both. As for tests, I will happily write them but first could you confirm that the approach here will be accepted?

andrewtoth avatar Feb 03 '24 19:02 andrewtoth

I don't know, I am the same external contributor as you. Judging by the general reaction of maintainers, one should hardly expect any attention in the near future

Mingun avatar Feb 03 '24 20:02 Mingun

It is interesting that I went on to try to solve another problem revolving flatten in #2751 and we actually ended up on very similar approach.

johnmave126 avatar Jun 02 '24 00:06 johnmave126