diff --git a/poem-openapi/CHANGELOG.md b/poem-openapi/CHANGELOG.md index 535b760177..6a58ef0da7 100644 --- a/poem-openapi/CHANGELOG.md +++ b/poem-openapi/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# Unreleased + +- implements `Serialize` and `Deserialize` for `poem_openapi::types::Any`. + # [5.1.0] 2024-09-08 - fix read_only_with_default test when only default features are enabled [#854](https://github.com/poem-web/poem/pulls) diff --git a/poem-openapi/src/types/any.rs b/poem-openapi/src/types/any.rs index 1085f2e23a..f78b84ad0e 100644 --- a/poem-openapi/src/types/any.rs +++ b/poem-openapi/src/types/any.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use serde::{de::DeserializeOwned, Serialize}; +use serde::{de::DeserializeOwned, Deserialize, Deserializer, Serialize, Serializer}; use serde_json::Value; use crate::{ @@ -66,6 +66,26 @@ impl ToXML for Any { } } +impl Serialize for Any { + #[inline] + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.0.serialize(serializer) + } +} + +impl<'de, T: DeserializeOwned> Deserialize<'de> for Any { + #[inline] + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + T::deserialize(deserializer).map(Self) + } +} + impl Type for Value { const IS_REQUIRED: bool = true;