Skip to content

Commit

Permalink
fix #883
Browse files Browse the repository at this point in the history
  • Loading branch information
sunli829 committed Sep 13, 2024
1 parent d36f88c commit 4af3314
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion poem-openapi/src/types/external/bson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl ParseFromMultipartField for ObjectId {

impl ToJSON for ObjectId {
fn to_json(&self) -> Option<Value> {
Some(serde_json::to_value(self).unwrap())
serde_json::to_value(self).ok()
}
}

Expand Down
2 changes: 1 addition & 1 deletion poem-openapi/src/types/external/floats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ macro_rules! impl_type_for_floats {

impl ToJSON for $ty {
fn to_json(&self) -> Option<Value> {
Some(Value::Number(Number::from_f64(*self as f64).unwrap()))
Number::from_f64(*self as f64).map(Value::Number)
}
}

Expand Down
4 changes: 2 additions & 2 deletions poem-openapi/src/types/external/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl ParseFromMultipartField for OffsetDateTime {

impl ToJSON for OffsetDateTime {
fn to_json(&self) -> Option<Value> {
Some(Value::String(self.format(&Rfc3339).unwrap_or_default()))
self.format(&Rfc3339).ok().map(Value::String)
}
}

Expand Down Expand Up @@ -129,7 +129,7 @@ macro_rules! impl_naive_datetime_types {

impl ToJSON for $ty {
fn to_json(&self) -> Option<Value> {
Some(Value::String(self.format($format_description).unwrap()))
self.format($format_description).ok().map(Value::String)
}
}
};
Expand Down

0 comments on commit 4af3314

Please sign in to comment.