Skip to content

Added json gem 3.x support while keeping the 2.x wire format. - #133

Merged
evolve75 merged 1 commit into
evolve75:masterfrom
Jack12816:json3
Oct 7, 2026
Merged

evolve75 merged 1 commit into
evolve75:masterfrom
Jack12816:json3

Conversation

@Jack12816

@Jack12816 Jack12816 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

@evolve75 First of all, thank you for maintaining RubyTree, it is a great gem and we rely on it in several of our own applications.

What is it good for

The json gem 3.0 removed the create_additions mechanism and the JSON.create_id accessor the JSON conversion of RubyTree was built on. With json 3.x installed, to_json raises because JSON.create_id is gone, and JSON.parse(..., create_additions: true) raises because the option no longer exists, so trees can neither be exported nor imported. The current ~> 2.0 constraint hides this by refusing json 3 at resolve time, which in turn blocks every application that already moved to json 3 (eg. Rails 8.1.4+) from installing RubyTree.

This change makes RubyTree work with the json gem 2.x and 3.x alike. The serialized format stays byte-identical, so documents written by earlier versions remain readable, and a new Tree::TreeNode.from_json rebuilds a tree on both majors.

What I did

  • emit the json_class tag from a gem-owned constant instead of JSON.create_id
  • add from_json to rebuild a tree through the parser's on_load callback
  • only materialize hashes tagged with the receiver class or one of its subclasses
  • keep json_create as the hook for the json 2.x create_additions path
  • allow json >= 2.21.2, < 4 in the gemspec
  • run the CI matrix against both json majors via per-major Gemfile variants
  • raise rubocop to 1.90+, regenerate the todo and load the extensions as plugins

@coveralls

coveralls commented Oct 7, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 96.235% (-0.1%) from 96.35% — Jack12816:json3 into evolve75:master

Signed-off-by: Hermann Mayer <hermann.mayer92@gmail.com>
@evolve75

evolve75 commented Oct 7, 2026

Copy link
Copy Markdown
Owner

@Jack12816 ,

Thank you! I really appreciate this. The change is well thought out and relevant. I have merged it into main. Expect a minor release later today.

@evolve75
evolve75 merged commit b40e566 into evolve75:master Oct 7, 2026
16 of 17 checks passed
@Jack12816

Copy link
Copy Markdown
Contributor Author

Thank you!

@Jack12816
Jack12816 deleted the json3 branch October 8, 2026 04:43
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.

3 participants