Ben Chuanlong Du's Blog

It is never too late to learn.

Handle Duplicated Keys in serde_yaml in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tips and Traps

  1. The YAML specification does not forbid duplicated keys.

  2. serde-yaml ignores duplicated keys except the last one silently, by default. To overwrite this behavior, you have to define your own struct and use the tag serde_with::rust::maps_duplicate_key_is_error .

    https://github.com/dtolnay/serde-yaml/issues/150

    https://users.rust-lang.org/t/how-can-i-handle-duplicate-fields-when-specifying-multiple-aliases-using-serde/46426

In [ ]:
 

Comments