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

Round trip serialization and deserialization fails when storing an Option<UnitStruct> #2462

Closed
alice-i-cecile opened this issue May 24, 2023 · 3 comments

Comments

@alice-i-cecile
Copy link

When writing to JSON, Some(UnitStruct) is serialized the same as None. This only seems to occur for structs with no data / fields.

I haven't investigated if this is a problem in other file formats.

This then causes the deserialization to not match the original value.

@alice-i-cecile
Copy link
Author

The field gets serialized as field: null. I suspect this is a JSON-specific limitation around handling enum values.

@dtolnay
Copy link
Member

dtolnay commented May 24, 2023

Neither serde nor serde_json makes round trip guarantees in general.

What JSON would you expect to get for each of the two values?

@alice-i-cecile
Copy link
Author

Given that unit structs are represented as null per the serde-json spec, I don't think there's a good solution. I'm very fine to leave this as "Won't Fix": this was merely a surprise that I felt was worth poking at and adding to the Google search results :)

@alice-i-cecile alice-i-cecile closed this as not planned Won't fix, can't repro, duplicate, stale May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants