openrtb_native1/request/data.rs
1/// 4.6 Data Request Object
2///
3/// The Data Object is to be used for all non-core elements of the native unit such as Brand Name,
4/// Ratings, Review Count, Stars, Download count, descriptions etc. It is also generic for future
5/// native elements not contemplated at the time of the writing of this document. In some cases,
6/// additional recommendations are also included in the Data Asset Types table.
7#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
8pub struct Data {
9 /// required; integer; -
10 /// Type ID of the element supported by the publisher. The publisher can display this
11 /// information in an appropriate format. See Data Asset Types table for commonly used
12 /// examples.
13 pub r#type: crate::DataAssetType,
14
15 /// optional; integer; -
16 /// Maximum length of the text in the element’s response.
17 #[serde(default, skip_serializing_if = "Option::is_none")]
18 pub len: Option<i32>,
19
20 /// optional; object; -
21 /// This object is a placeholder that may contain custom JSON agreed to by the parties to
22 /// support flexibility beyond the standard defined in this specification.
23 #[serde(default, skip_serializing_if = "Option::is_none")]
24 pub ext: Option<serde_json::Map<String, serde_json::Value>>,
25}
26
27#[cfg(test)]
28mod test {
29 use super::*;
30
31 #[test]
32 fn json() -> serde_json::Result<()> {
33 let json = r#"{"type":1}"#;
34 let o1 = Data {
35 r#type: crate::DataAssetType::Sponsored,
36 len: None,
37 ext: None,
38 };
39 assert_eq!(serde_json::to_string(&o1)?, json);
40 assert_eq!(o1, serde_json::from_str::<Data>(json)?);
41
42 Ok(())
43 }
44}