rocket/serde/
mod.rs

1//! Serialization and deserialization support.
2//!
3//! * JSON support is provided by the [`Json`](json::Json) type.
4//! * MessagePack support is provided by the [`MsgPack`](msgpack::MsgPack) type.
5//! * UUID support is provided by the [`UUID`](uuid) type.
6//!
7//! Types implement one or all of [`FromParam`](crate::request::FromParam),
8//! [`FromForm`](crate::form::FromForm), [`FromData`](crate::data::FromData),
9//! and [`Responder`](crate::response::Responder).
10//!
11//! ## Deriving `Serialize`, `Deserialize`
12//!
13//! For convenience, Rocket re-exports `serde`'s `Serialize` and `Deserialize`
14//! traits and derive macros from this module. However, due to Rust's limited
15//! support for derive macro re-exports, using the re-exported derive macros
16//! requires annotating structures with `#[serde(crate = "rocket::serde")]`:
17//!
18//! ```rust
19//! use rocket::serde::{Serialize, Deserialize};
20//!
21//! #[derive(Serialize, Deserialize)]
22//! #[serde(crate = "rocket::serde")]
23//! struct MyStruct {
24//!     foo: String,
25//! }
26//! ```
27//!
28//! If you'd like to avoid this extra annotation, you must depend on `serde`
29//! directly via your crate's `Cargo.toml`:
30//!
31//! ```toml
32//! [dependencies]
33//! serde = { version = "1.0", features = ["derive"] }
34//! ```
35
36#[doc(inline)]
37pub use serde::ser::{Serialize, Serializer};
38
39#[doc(inline)]
40pub use serde::de::{Deserialize, DeserializeOwned, Deserializer};
41
42#[doc(hidden)]
43pub use serde::*;
44
45#[cfg(feature = "json")]
46#[cfg_attr(nightly, doc(cfg(feature = "json")))]
47pub mod json;
48
49#[cfg(feature = "msgpack")]
50#[cfg_attr(nightly, doc(cfg(feature = "msgpack")))]
51pub mod msgpack;
52
53#[cfg(feature = "uuid")]
54#[cfg_attr(nightly, doc(cfg(feature = "uuid")))]
55pub mod uuid;