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

Deserialization for RangeFrom and RangeTo doesn't work #2652

Closed
emilbonnek opened this issue Nov 21, 2023 · 0 comments · Fixed by #2653
Closed

Deserialization for RangeFrom and RangeTo doesn't work #2652

emilbonnek opened this issue Nov 21, 2023 · 0 comments · Fixed by #2653

Comments

@emilbonnek
Copy link
Contributor

emilbonnek commented Nov 21, 2023

It seems that the deserialization for RangeFrom and RangeTo has been switched around such that RangeTo expects a "start" and RangeFrom expects a "end". They are correct in the serialization though.

See the following test:

#[cfg(test)]
mod tests {
    use std::ops::{Range, RangeFrom, RangeTo};

    use serde_json;

    #[test]
    fn deserialize_range_to() {
        let json = r#"{"end": 173}"#;
        let result: Result<RangeTo<u32>, serde_json::Error> = serde_json::from_str(json);
        assert!(result.is_ok(), "Deserialization failed: {:?}", result); // Fails
    }

    #[test]
    fn deserialize_range_from() {
        let json = r#"{"start": 173}"#;
        let result: Result<RangeFrom<u32>, serde_json::Error> = serde_json::from_str(json);
        assert!(result.is_ok(), "Deserialization failed: {:?}", result); // Fails
    }

    #[test]
    fn deserialize_range() {
        let json = r#"{"start": 173, "end": 176}"#;
        let result: Result<Range<u32>, serde_json::Error> = serde_json::from_str(json);
        assert!(result.is_ok(), "Deserialization failed: {:?}", result); // Passes
    }
}

It seems to have been introduced in #2471.

@emilbonnek emilbonnek changed the title Deserialization for RangeFrom and RangeTo doesn Deserialization for RangeFrom and RangeTo doesn't work Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant