diff --git a/src/file_builders/wivrn_config.rs b/src/file_builders/wivrn_config.rs index c591fec..a28c2cb 100644 --- a/src/file_builders/wivrn_config.rs +++ b/src/file_builders/wivrn_config.rs @@ -3,6 +3,7 @@ use crate::{ xdg::XDG, }; use serde::{Deserialize, Serialize}; +use serde_json::{Map, Value}; use std::{ fmt::Display, path::{Path, PathBuf}, @@ -92,6 +93,9 @@ pub struct WivrnConfEncoder { pub offset_y: Option, #[serde(skip_serializing_if = "Option::is_none")] pub group: Option, + /// contains unknown fields + #[serde(flatten)] + other: Map, } impl Default for WivrnConfEncoder { @@ -104,6 +108,7 @@ impl Default for WivrnConfEncoder { offset_x: Some(0.0), offset_y: Some(0.0), group: None, + other: Map::default(), } } } @@ -129,6 +134,9 @@ pub struct WivrnConfig { pub application: Option, #[serde(default)] pub tcp_only: bool, + /// contains unknown fields + #[serde(flatten)] + other: Map, } impl Default for WivrnConfig { @@ -139,6 +147,7 @@ impl Default for WivrnConfig { encoders: vec![], application: None, tcp_only: false, + other: Map::default(), } } } @@ -190,6 +199,9 @@ mod tests { Some(WivrnConfigApplication::Str("foobar".into())) ); assert!(!conf.tcp_only); + assert!(serde_json::to_string(&conf) + .unwrap() + .contains("\"extraneous\":\"field\",\"other\":{\"weird\":[\"stuff\"]}")); let conf = get_wivrn_config_from_path(Path::new("./test/files/wivrn_config2.json")) .expect("Couln't find wivrn config 2"); assert_eq!( diff --git a/test/files/wivrn_config.json b/test/files/wivrn_config.json index 9f36f8c..fe3eb8f 100644 --- a/test/files/wivrn_config.json +++ b/test/files/wivrn_config.json @@ -11,5 +11,7 @@ "offset_y": 0.0 } ], - "application": "foobar" + "application": "foobar", + "extraneous": "field", + "other": {"weird": ["stuff"]} }