Skip to content
This repository has been archived by the owner on Aug 15, 2021. It is now read-only.

Allow integer map keys to accept string-encoded integers #207

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Timmmm
Copy link

@Timmmm Timmmm commented Aug 3, 2020

This fixes #205. I know this project is semi-abandoned and you don't want to add code you haven't read (totally understandable) so let me know if you think this will never be merged and in that case I guess we will have to fork this.

Note most of the code for impl<'de, 'a, R> de::Deserializer<'de> for MapKey<'a, R> was copied from serde_json.

When serde attempts to deserialise a HashMap<i32, T> for example, with serde_json it will accept keys that are string-encoded versions of integers. This is because JSON only supports string keys. However this means that when you save data using serde_json, convert it to CBOR and then try and read it using serde_cbor, it will fail because CBOR does not accept string-encoded integer keys.

This commit changes that so that it does.

Tim Hutt added 2 commits August 3, 2020 16:24
When serde attempts to deserialise a HashMap<i32, T> for example, with serde_json it will accept keys that are string-encoded versions of integers. This is because JSON only supports string keys. However this means that when you save data using serde_json, convert it to CBOR and then try and read it using serde_cbor, it will fail because CBOR does not accept string-encoded integer keys.

This commit changes that so that it does.
@Timmmm
Copy link
Author

Timmmm commented Aug 3, 2020

Also I'm not exactly sure what accept_packed/accept_named are so this might not be right if either of those are disabled.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deserialisation of maps does not parse string keys to integers
1 participant