Repository navigation
Support Java flat serialization for Rune choices - #77
Merged
Merged
Conversation
Read and write choices using generated discriminator dispatch maps. Support deeply nested choices, basic and enum options, and field metadata and reference wrappers. Preserve native Python construction and ObjectBuilder behavior. BREAKING CHANGE: JSON choice input requires the flat discriminated format. Regenerate choice models with _RUNE_CHOICE and _CHOICE_DISPATCH.
4 tasks done
plamen-neykov
marked this pull request as draft
November 13, 2026 18:36
Share the dispatch-table guard across deserialization and serialization. Raise RuntimeError with model-regeneration guidance when _CHOICE_DISPATCH is missing. Add regression coverage for reading and for writing primitive, enum, and data options.
plamen-neykov
marked this pull request as ready for review
November 13, 2026 19:10
plamen-neykov
marked this pull request as draft
November 13, 2026 20:32
plamen-neykov
marked this pull request as ready for review
November 13, 2026 20:33
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.
Summary
Rune choices now serialize directly to their selected leaf using Java's
flat JSON representation. For example,
ChoiceAB(A=A(value="foo"))writes{"@type": "example.A", "value": "foo"}._CHOICE_DISPATCHmaps,including deeply nested choices.
@data.Compatibility
Choice models require regeneration with a generator that emits
_RUNE_CHOICEand_CHOICE_DISPATCH.JSON readers require the flat format and a valid discriminator. Existing JSON
using nested option field names must be regenerated. Python constructors,
model_validate, and ObjectBuilder continue to accept native field dictionaries.Ordinary types with a
one-ofcondition retain their existing JSON structure.The implementation assumes valid DSL-generated choices, which cannot declare
type-level metadata.
Validation
failure in
test_init_invalid_directory_or_module.with and without a Python namespace prefix.
Java metadata-wrapper payload.
Generator follow-up
Metadata-wrapped enum options require FQN discriminator keys. The current
generator still emits short names for the enum case.
Relationship to #75
This PR builds on @dschwartznyc's initial work on Java-compatible choice
serialization in #75. It retains and adapts the metadata-wrapper handling,
the distinction between option references and whole-choice references, and
the metaclass/context approach for distinguishing native Python construction
from JSON validation.
The implementation uses generated
_CHOICE_DISPATCHtables for routing andadds coverage for deeply nested choices, builders, serialization filters,
and namespace prefixes.
This PR supersedes #75. Once this PR is merged, #75 can be closed as superseded.
Closes #55