Easiest to show with an example:
#[derive(Facet, Clone, PartialEq, Debug)]
pub struct Wrapper {
value: String,
#[facet(flatten)]
inner: AdjacentlyTagged,
}
#[derive(Facet, Clone, PartialEq, Debug)]
#[repr(u8)]
#[facet(tag = "tag", content = "content")]
pub enum AdjacentlyTagged {
Foo { foo: String },
Bar { bar: String },
}
fn main() {
let value = Wrapper {
value: "".to_string(),
inner: AdjacentlyTagged::Foo { foo: "".to_string() },
};
let json = facet_json::to_string(&value).unwrap();
println!("Serialized:\n{json}");
println!("Deserialized:\n{:?}", facet_json::from_str::<Wrapper>(&json));
}
(Tested with facet = "=0.44.1" and facet-json locked to 451b761)
facet_json serializes this type as:
{
"value": "",
"Foo": {
"tag": "Foo",
"content": {"foo": ""}
}
}
...which is to say, the inner field gets wrapped in an extra field named after its variant, as if it were externally-tagged (I think). Instead, I'd expect this (i.e. what serde_json does):
{
"value": "",
"tag": "Foo",
"content": {"foo": ""}
}
Deserialization fails with either version of the JSON.
Easiest to show with an example:
(Tested with
facet = "=0.44.1"andfacet-jsonlocked to 451b761)facet_jsonserializes this type as:{ "value": "", "Foo": { "tag": "Foo", "content": {"foo": ""} } }...which is to say, the
innerfield gets wrapped in an extra field named after its variant, as if it were externally-tagged (I think). Instead, I'd expect this (i.e. whatserde_jsondoes):{ "value": "", "tag": "Foo", "content": {"foo": ""} }Deserialization fails with either version of the JSON.