#[serde(flatten)] with nested struct fails to deserialize numeric query parameters
I have the following structs:
```
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PaginationQuery {
#[serde(default = "default_current")]
pub current: u16,
#[serde(default = "default_page_size")]
pub page_size: u8,
#[serde(flatten)]
pub extra: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProjectPaginationQuery {
#[serde(flatten)]
pub project_info: ProjectInfo, // another struct
#[serde(flatten)]
pub pagination: PaginationQuery,
}
```
When I query the endpoint:
`http://localhost:5173/api/node/get_data_list?current=1&pageSize=20&projectName=test&tableName=test`
PaginationQuery works perfectly and correctly deserializes the parameters.
However, when I try to use ProjectPaginationQuery, I get the following error:
`Query deserialize error: invalid type: string "1", expected u16`
It seems that when flattening into a nested struct, numeric query parameters are interpreted as strings instead of the expected numeric type.
**Environment:**
[dependencies]
ntex = { version = "3", features = ["tokio","cookie"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
关闭于 2026-04-04 1 条评论