-
Notifications
You must be signed in to change notification settings - Fork 266
Open
Labels
arraysIssues related to mapping XML content onto arrays using serdeIssues related to mapping XML content onto arrays using serdeserdeIssues related to mapping from Rust types to XMLIssues related to mapping from Rust types to XML
Description
Hi, cool project!
Consider these two types using serde (de)serialize:
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct FooType {
#[serde(rename = "a-list")]
pub a_list: ListType,
}
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct ListType{
#[serde(default, rename = "$text")]
pub content: Vec<String>
}This creates xml such as <test><a-list>A B</a-list></test>.
Now consider this slight adaptation:
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct BarType {
#[serde(default, rename = "@a-list")]
pub a_list: ListType,
}I expect this to create xml such as <test a-list="A B"/>, but it fails with
Unsupported("cannot serialize struct
ListTypeas an attribute or text content value")
I know that if I change ListType to simply
type ListType = Vec<String>the second case works. But then, the first case does not serialize correctly: <test><a-list>A</a-list><a-list>B</a-list></test>
Is there a way to define a single ListType in such a way that both
<test><a-list>A B</a-list></test><test a-list="A B"/>
can be serialized?
Thanks a lot!!
Metadata
Metadata
Assignees
Labels
arraysIssues related to mapping XML content onto arrays using serdeIssues related to mapping XML content onto arrays using serdeserdeIssues related to mapping from Rust types to XMLIssues related to mapping from Rust types to XML