Can you fix this code?
You can implement Serialize and Deserialize for Student
yourself, that should solve the issue. (without using #[derive]
)
how to do it?
If you look at the documentation I linked to, there is an example for Serialize. For Deserialize see this link on how to implement it.
The indexmap
crate has a serde-1
feature that you must enable in your Cargo.toml
to get its implementations. Then you should be able to derive your own type.
Ahh, that’s an even better. I wasn’t familiar with indexmap
so I didn’t know about that. Thanks for the help!
Also for future reference, you can do something like this to serialize things with serde.
Can you edit to make my code work completely?
I don’t know how to affect the crate features on the playground, but locally I found that your code works as-is with these dependencies in Cargo.toml:
[dependencies]
indexmap = { version = "1", features = ["serde-1"] }
serde = "1"
serde_derive = "1"
serde_json = "1"