Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for #[deser(flatten)] #9

Closed
jonasbb opened this issue Feb 6, 2022 · 3 comments
Closed

Add support for #[deser(flatten)] #9

jonasbb opened this issue Feb 6, 2022 · 3 comments
Labels
design Design considerations

Comments

@jonasbb
Copy link

jonasbb commented Feb 6, 2022

Hi, I am not sure if that is the correct way for feedback. I could not find if this is a feature being addressed or if there is a plan for providing something similar in deser. At least, I want to contribute it as a point to be aware of.

serde has a long-standing issue about internal buffering which interacts with a lot features and tends to break deserialization unexpectedly: serde-rs/serde#1183 (Example)
Internal buffering is used to implement the flatten attribute, untagged and adjacently tagged enums.

The problem in the example is that serde_json "knows" how to deserialize a HashMap<i64, i64> (by treating string keys as numbers), but due to buffering it turns into a Map<String, i64> which then cannot be deserialized. The problem is also that the Inner type works well on its own, but by being included in the Outer type it starts failing.

@mitsuhiko
Copy link
Owner

So far it doesn't but this issue is one I want to try to address. Generally internal buffering will absolutely be necessary to address this issue but internal buffering is tricky. My general goal is to have an extensible internal data model but I'm not sure yet what the best approach here is.

Both serde-rs/serde#1183 and serde-rs/serde#1463 are issues I hit with serde and are tricky to address in its current design but I want to try to address here.

@mitsuhiko mitsuhiko added the design Design considerations label Feb 6, 2022
@mitsuhiko mitsuhiko changed the title How does deser handle buffering for flatten or untagged enums? Add support for #[deser(flatten)] Feb 7, 2022
@mitsuhiko
Copy link
Owner

Basic support for this landed now but I am not entirely convinced yet that the approach here is the best one. That said, I did chose to implement flattening by "reaching" into the inner deserializer without buffering, which should be less error prone.

@mitsuhiko
Copy link
Owner

I'm closing this as resolved for now, but I am sure that there will be multiple iterations about this before this feature can be considered implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design considerations
Projects
None yet
Development

No branches or pull requests

2 participants