Merge pull request #184 from alanhdu/master

Serialize nested array of tables correctly
This commit is contained in:
Alex Crichton 2017-06-01 08:36:08 -05:00 committed by GitHub
commit 10d15333b4
5 changed files with 45 additions and 5 deletions

View file

@ -308,6 +308,26 @@ impl<'a> Serializer<'a> {
State::Array { .. } => true,
_ => false,
};
// Unlike [..]s, we can't omit [[..]] ancestors, so be sure to emit table
// headers for them.
let mut p = state;
if let State::Array { first, parent, .. } = *state {
if first.get() {
p = parent;
}
}
while let State::Table { first, parent, .. } = *p {
p = parent;
if !first.get() {
break;
}
if let State::Array { parent: &State::Table {..}, ..} = *parent {
self.emit_table_header(parent)?;
break;
}
}
match *state {
State::Table { first, .. } |
State::Array { parent: &State::Table { first, .. }, .. } => {

View file

@ -61,10 +61,6 @@ macro_rules! error {
})
}
macro_rules! decode( ($t:expr) => ({
t!($t.try_into())
}) );
macro_rules! map( ($($k:ident: $v:expr),*) => ({
let mut _m = BTreeMap::new();
$(_m.insert(stringify!($k).to_string(), $v);)*

View file

@ -189,3 +189,7 @@ test!(example4,
test!(example_bom,
include_str!("valid/example-bom.toml"),
include_str!("valid/example.json"));
test!(table_array_nest_no_keys,
include_str!("valid/table-array-nest-no-keys.toml"),
include_str!("valid/table-array-nest-no-keys.json"));

View file

@ -0,0 +1,14 @@
{
"albums": [
{
"songs": [{}, {}]
}
],
"artists": [
{
"home": {
"address": {}
}
}
]
}

View file

@ -0,0 +1,6 @@
[[ albums ]]
[[ albums.songs ]]
[[ albums.songs ]]
[[ artists ]]
[ artists.home.address ]