Skip to content

Sort RFC 8785 keys after as_json conversion - #1104

Open
ydah wants to merge 1 commit into
ruby:masterfrom
ydah:fix-rfc8785-converted-key-order
Open

ydah wants to merge 1 commit into
ruby:masterfrom
ydah:fix-rfc8785-converted-key-order

Conversation

@ydah

@ydah ydah commented Oct 8, 2026

Copy link
Copy Markdown
Member

Apply as_json before sorting keys by UTF-16 code units, and reuse the converted keys for output.

coder = JSON::Coder.new(rfc8785: true) { |object| object.year.to_s }
coder.dump({ Time.utc(1999) => 1, "1999!" => 2 })
# Before: {"1999!":2,"1999":1}
# After:  {"1999":1,"1999!":2}

Call the callback once per converted key and reject collisions when building the converted hash to avoid overwriting entries.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant