Skip to main content

japi/
meta.rs

1use serde_json::Value;
2use std::collections::BTreeMap;
3
4/// An object containing non-standard meta information
5///
6/// See the [JSON:API docs](https://jsonapi.org/format/#document-meta) for more information
7pub type Meta = BTreeMap<String, Value>;
8
9#[cfg(test)]
10mod test {
11    use super::*;
12    use serde_json::{self, json};
13
14    #[test]
15    fn serde() {
16        let mut meta = Meta::new();
17        meta.insert("a".into(), json!("a"));
18        meta.insert("b".into(), Value::Null);
19        let s = serde_json::to_string(&meta).unwrap();
20        assert_eq!(s, "{\"a\":\"a\",\"b\":null}");
21        let meta2 = serde_json::from_str(&s).unwrap();
22        assert_eq!(meta, meta2);
23    }
24}