Repository navigation
fix: write the top-level object's metadata in rune_serialize - #70
Merged
Merged
Conversation
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.
Closes #64.
Problem
The top-level object's metadata, such as
@keyor@key:external, was read and kept on the object, butrune_serializedidn't write it. The same metadata on an object held in a field was written.An object's metadata is written by the serializer of the field that holds it. The top-level object isn't held in a field, and
rune_serializeonly added@type,@modeland@versionto the top level.For example, reading
{"@key": "k1", "party": {"name": "A"}}into aTradeand writing it again gave{"@type": ..., "@model": ..., "@version": ..., "party": {"name": "A"}}, without"@key": "k1".Change
rune_serializeadds the object's own metadata to the top level, after@versionis set:The # type: ignore matches the root_meta line above it.
New test/test_top_level_metadata.py, 8 tests, using the classes rune-python-generator produces for a type with [metadata key], an attribute of such a type, and a type without metadata. It covers @key, @key:external, both together, a top-level key alongside a key on a field, writing with validation on, @type, @model and @Version still being written, an object without metadata, and writing twice.
Testing
Note
Java writes @key:external on the top-level object, but leaves out an @key that nothing refers to, as it does for any @key. Python doesn't leave out unreferenced keys anywhere (#65), so this change writes the top-level @key as it was read.