-
Notifications
You must be signed in to change notification settings - Fork 44
Description
Problem
The current FilterStructToMap function returns a standard map[string]any. In Go, map iteration order is non-deterministic, and when marshaled with encoding/json, the keys are sorted alphabetically.
This behavior causes a mismatch: JSON generated directly from a struct preserves the field declaration order, but JSON generated after filtering through FilterStructToMap ends up alphabetically ordered.
While not a breaking issue for most parsers, this inconsistency is a poor user experience and can affect processes that rely on stable and predictable output order.
Proposal
To resolve this, we propose changing the return type of FilterStructToMap from map[string]any to *mapsutil.OrderedMap[string, any].
The OrderedMap type, which is already part of this utils library, is a special map implementation that preserves the insertion order of keys. By returning this type, we can guarantee a deterministic JSON output that matches the original struct field order.
This change will improve the utility for any tool that uses it for JSON serialization tasks.