-
I added the following test code (for processing strings), but it didn't work. #[derive(Object, Serialize, Deserialize, Debug)]
struct TestReq {
#[serde(with = "trim")]
code: String,
}
pub struct Api;
#[OpenApi]
impl Api {
#[oai(path = "/test", method = "post")]
async fn test(&self, test_req: Json<TestReq>) -> Result<i32> {
...
}
}
pub mod trim {
use serde::{self, Deserialize, Deserializer, Serializer};
pub fn serialize<S>(str: &str, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let s = str.trim();
serializer.serialize_str(s)
}
pub fn deserialize<'de, D>(deserializer: D) -> Result<String, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(s.trim().to_string())
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
sunli829
Mar 4, 2022
Replies: 1 comment 2 replies
-
You cannot do this, |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
gudaoxuri
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You cannot do this,
poem-openapi
does not useserde
to support serialization, currently you can only define a new type and implement thepoem_openapi::Type
trait for it.