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 array deserialize support for duplicate keys (without square brackets) #116

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

vegardgs-ksat
Copy link

This PR expands support to handle duplicate keys without square brackets to be parsed as an unordered sequence.

Given the following query params: id=abc&id=def

#[derive(Debug, Deserialize)]
struct Query {
    id: Vec<String>,
}

let query = "id=abc&id=def";
let result: Result<Query, _> = qs::from_str(query);
assert!(result.is_ok());
assert_eq!(result.unwrap(), Query { id: vec!["abc", "def"] });

This PR closes #35.

Given the discussion and prior position taken to not accept this functionality, I am prepared that this may not be accepted. I would like input from the community for alternative crates that may be a better fit. In general, I am looking a complete parsing solution for typical use-cases encountered from OpenAPI specifications for my server-side query parameter handling.

@vegardgs-ksat vegardgs-ksat force-pushed the add-array-nonindex-support branch from 2ffbde2 to d55bd21 Compare December 17, 2024 20:55
@vegardgs-ksat vegardgs-ksat force-pushed the add-array-nonindex-support branch from d55bd21 to 28f6925 Compare December 17, 2024 21:51
@k01e-01
Copy link

k01e-01 commented Jan 13, 2025

this solved my problem, +1

perhaps this should be handled as its own separate config option?

pub struct Config {
    max_depth: usize,
    strict: bool,
    array_nonindex: bool,
};

impl Config {
    pub fn new(max_depth: usize, strict: bool, array_nonindex: bool) -> Self {
        Self { max_depth, strict, array_nonindex }
    }
}

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

Successfully merging this pull request may close these issues.

Also allowing lists to be represented with [] or implicitly
2 participants