Serde -- map of struct to struct

Hello,

I have a struct looking like this

struct Something {
   map: HashMap<A, B>,
   integer: u32,
}

A and B are other structs for which I derived serde::Serialize and serde::Deserialize.

However, I can't convert that to json since keys of map are not strings. Is there a data format that would allow me to do that? If not, is there a trick with serde (or other library) to easily convert map to a list of pairs or something like that.

In the end, I don't care how the data are saved and loaded. I just want to be able to do it.

1 Like

One approach is described here.

Edit: The serde_with crate seems to implement this kind of functionality (alternative/older API).

2 Likes

I was able to tweak something using the serde_with crate. Thank you!