Repository navigation
Preserve shared S7 classes through JSON round trips - #120
Merged
Merged
Conversation
Contributor
Author
|
Thanks for maintaining typedjson! I'm planning to submit the next version of S7 to CRAN on November 16 (see RConsortium/S7#786). Would you be able to merge these compatibility changes and submit an updated version of typedjson to CRAN before then? Please let me know if you need more time or if there’s anything I can help with. |
…20261012 # Conflicts: # src/read.cpp
The test from main expects the class at `attr(x, "S7_class")`, but S7 1.0.0 writes `_S7_class`. The round-trip helper now takes its comparison from the caller, since lintr flags a call from one helper file into another.
In typedjson a reference is already a class recorded by its name, so a `reference` key gave the word a second meaning. A class that an older S7 built now reads back as the class itself, the way S7 1.0.0 stores it, and an older S7 refuses a class reference by the version it needs.
A read with `code = FALSE` named only `S7_class`, though S7 1.0.0 writes `_S7_class`.
The round-trip tests fell back to comparing every corpus value by structure once `identical()` failed, which would let a regression in any other value pass as an equivalent one.
The docs named only `S7_class`, which S7 1.0.0 renamed `_S7_class` and fills with a class reference. The NEWS entry now says what changed for a user rather than that something did.
Owner
|
I merged main into this branch and pushed a few changes on top, so that the fix can go out with typedjson 0.1.2. Thanks for the PR. Some tweaks:
The fix reads three S7 internals: the |
nbenn
approved these changes
Nov 20, 2026
This was referenced Nov 20, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With updated S7, JSON round trips rebuild nested constructor environments, lose shared class definitions, and skip property validation because the reader only recognizes the older class attribute.
Record S7 class references through the existing S7 state tag, preserve repeated class definitions in reference bookkeeping, and omit the constructor environment that
new_class()recreates. Resolve the decoded class throughS7_class()and validate the current instance representation. Objects read from one document retain their shared class, and re-encoding that document stays stable.Corpus checks compare reconstructed environments by structure and sharing topology, matching the format's existing equivalence contract. The S3-property fixture is defined outside the test runner namespace. Constructor bindings resolved by newer S7 are checked as data, while their promise-based refusal cases remain covered with S7 0.2.2.