Skip to content

Commit

Permalink
Output nested tables last
Browse files Browse the repository at this point in the history
The TOML format has a restriction that if a table itself contains
tables, all keys with non-table values must be emitted first. This led
to the following error:

$ echo '{"a": {}, "b": 1}' | rq -T
[ERROR] [rq] Encountered: TOML serialize error
[ERROR] [rq] Caused by: values must be emitted before tables

Fix this by using tables_last to output the tables after other keys.

This affects all output formats that serialize using serde. The ordering
is unimportant in the other formats, so that is harmless. The
performance impact should be small.
  • Loading branch information
JoelColledge committed Nov 12, 2021
1 parent 99b4946 commit 2785d9a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use serde_json;
use std::collections;
use std::fmt;
use std::io;
use toml::ser as toml_ser;

pub mod avro;
pub mod cbor;
Expand Down Expand Up @@ -159,7 +160,7 @@ impl serde::ser::Serialize for Value {
Self::Bytes(ref v) => v.serialize(s),

Self::Sequence(ref v) => v.serialize(s),
Self::Map(ref v) => v.serialize(s),
Self::Map(ref v) => toml_ser::tables_last(v, s),
}
}
}
Expand Down

0 comments on commit 2785d9a

Please sign in to comment.