From 2785d9a7b9cb43e163cfc8f6d73af01107de97bc Mon Sep 17 00:00:00 2001 From: Joel Colledge Date: Fri, 12 Nov 2021 10:03:53 +0100 Subject: [PATCH] Output nested tables last 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. --- src/value/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/value/mod.rs b/src/value/mod.rs index 26565a14..9d475f21 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -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; @@ -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), } } }