-
-
Notifications
You must be signed in to change notification settings - Fork 822
Deserialize object/map while maintaining order #269
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
Comments
Using an ordered map type would be more appropriate than LinkedHashMap will work for JSON but unfortunately not for serde-yaml because serde-yaml uses yaml_rust which uses a BTreeMap for maps. |
I made a PR that adds a preserve_order feature to yaml-rust: chyh1990/yaml-rust#16. Once that merges and yaml-rust does a 0.3.1 release, I can update serde-yaml to depend on it: dtolnay/serde-yaml#14. I will check off the PRs as they merge: |
Awesome, thanks so much! If you need anything from me feel free to ask 😊
|
All set here, I think. The answer is to use an ordered map type (linked-hash-map and linear-map both come with serde support). For YAML you additionally need to set the |
Should we add this feature to the json value type? |
Awesome, thanks! @oli-obk, maybe that should be a fresh issue? |
I filed serde-rs/json#54 to follow up on adding a feature flag to use linked-hash-map in serde_json::Value. |
bigint: Create the parsing error better for nested `+` If a `+` is encountered in the middle of parsing a BigUint, this should generate an `ParseIntError::InvalidDigit`. Since we can't create that directly, we get it by trying to parse a `u64` from this point, but of course `+` is a perfectly valid prefix to a `u64`. Now we include the previous character in the string passed to `u64`, so it has proper parsing context to understand what's in error. Fixes serde-rs#268.
Is there a way to deserialize a map (like a JSON or YAML object) while maintaining the order of key/value pairs? The
BTreeMap
type deserializes into kind of what I want except it does not maintain order.Deserializing a map to
Vec<(K, V)>
would be perfect.The text was updated successfully, but these errors were encountered: