I've got two services using canonical_json to output some JSON for signing. Unfortunately, they disagree on the order of keys in their output. One of them correctly outputs in lexicographical order, one of them does not.
I've tracked this down to the preserve_order feature flag in serde_json. If this is present then serde_json::map::Mapuses an IndexMap rather than a BTreeMap, and it seems canonical_json relies on this BTreeMap to output data in the correct order.
This would be relatively easy to fix if I'd requested the preserve_order flag myself but I didn't. There's a transient dependency somewhere in my tree that's requested it...
This appears to be a limitation in the serde_json::ser::Formatter trait. It does not allow implementors to control the order of keys. See serde-rs/json#945.
I've got two services using
canonical_json
to output some JSON for signing. Unfortunately, they disagree on the order of keys in their output. One of them correctly outputs in lexicographical order, one of them does not.I've tracked this down to the
preserve_order
feature flag inserde_json
. If this is present thenserde_json::map::Map
uses anIndexMap
rather than aBTreeMap
, and it seemscanonical_json
relies on thisBTreeMap
to output data in the correct order.This would be relatively easy to fix if I'd requested the
preserve_order
flag myself but I didn't. There's a transient dependency somewhere in my tree that's requested it...