Skip to content

statsig-rust unconditionally enables serde_json/preserve_order, causing workspace-wide side effects for consumers #41

@max-zheng

Description

@max-zheng

Problem

statsig-rust (since v0.15.1) unconditionally enables serde_json's preserve_order feature:

[dependencies.serde_json]
version = "1.0.143"
features = [
    "float_roundtrip",
    "raw_value",
    "preserve_order",
]

Due to Cargo's feature unification, this changes serde_json::Value's internal Map from BTreeMap (alphabetically sorted keys) to IndexMap (insertion-order keys) for every crate in the consumer's workspace — not just statsig-rust.

Impact

Adding statsig-rust to any crate in a workspace silently changes serialization behavior for all other crates:

  • JSON output key ordering changes from alphabetical to insertion order
  • Test snapshots break
  • Generated files (e.g. OpenAPI specs) produce unnecessary diffs
  • Deterministic serialization assumptions break

These issues are extremely hard to trace back to a transitive dependency. Having this side effect can definitely make customers less likely to adopt this crate since it will have workspace-wide side effects to one of the most widely used rust crates.

Suggestion

Ideally, remove the preserve_order dependency entirely by rewriting any code that relies on insertion-order JSON keys. If that's not feasible, please make it opt-in via a feature flag instead:

[features]
preserve_order = ["serde_json/preserve_order"]

[dependencies.serde_json]
version = "1.0.143"
features = [
    "float_roundtrip",
    "raw_value",
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions