warp icon indicating copy to clipboard operation
warp copied to clipboard

Query data did not match any variant of untagged enum

Open 51yu opened this issue 2 years ago • 2 comments

Version 0.3.2

Platform MacOS

Description I have query body defined as

#[derive(Deserialize, Serialize)]
#[serde(untagged)]
pub enum MyQuery {
    TypeA {
        foo_id: Uuid,
        bar_id: Uuid,
        buzz_id_maybe: Option<Uuid>,
        limit: i64,
    },
    TypeB {
        buzz_id: Uuid,
        foo_id_maybe: Option<Uuid>,
        limit: i64,
    },
}

I sent request with query string

foo_id=FOO-UUID&bar_id=BAR-UUID&limit=10

or

foo_id=FOO-UUID&bar_id=BAR-UUID&buzz_id_maybe=BUZZ-UUID&limit=10

both return 400

failed to decode query string, Error("data did not match any variant of untagged enum MyQuery")

but both should match TypeA of MyQuery, any suggestion ?

51yu avatar Aug 20 '22 23:08 51yu

Looking into thread https://github.com/serde-rs/serde/issues/1183#issuecomment-668324535 found solution https://docs.rs/serde_with/latest/serde_with/struct.DisplayFromStr.html

51yu avatar Aug 21 '22 03:08 51yu

duplicate to https://github.com/nox/serde_urlencoded/issues/66

51yu avatar Aug 21 '22 03:08 51yu