You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am unable to preserve the order of my fields in json-serialized responses. The serde_json crate has a preserve_order feature but it is not exposed by the rocket crate.
Ideal Solution
No response
Why can't this be implemented outside of Rocket?
I believe if we want to use rocket's Json guard and have preserve_order then we are forced to re-export the feature on rocket's serde_json.
Are there workarounds usable today?
No response
Alternative Solutions
No response
Additional Context
No response
System Checks
I do not believe that this feature can or should be implemented outside of Rocket.
I was unable to find a previous request for this feature.
The text was updated successfully, but these errors were encountered:
We are not technically required to re-export the feature. If you also add an explicit dependency on serde_json, and enable the preserve_order feature, it will also enable it for Rocket.
serde_json = { version = "^10.0.26", features = ["preserve_order"] }
However, this only helps for the builtin serde_json::Value (or the json!{} macro). If you are serializing a custom struct (which you should prefer, since it makes it easier to document what your responses should look like), you will need to switch away from a HashMap or BTreeMap, since these data types will change the order of inserted elements. I would recommend using IndexMap, from the indexmap crate, which is a map data structure that preserves insertion order.
What's missing?
I am unable to preserve the order of my fields in json-serialized responses. The serde_json crate has a preserve_order feature but it is not exposed by the rocket crate.
Ideal Solution
No response
Why can't this be implemented outside of Rocket?
I believe if we want to use rocket's Json guard and have preserve_order then we are forced to re-export the feature on rocket's serde_json.
Are there workarounds usable today?
No response
Alternative Solutions
No response
Additional Context
No response
System Checks
The text was updated successfully, but these errors were encountered: