Repository navigation
Write parameter domains as names in JSONProducer - #206
Merged
Merged
Conversation
JSONProducer had no case for Domain values: a domain (a shared singleton)
was written as {spec: "...PositiveReal"} the first time and "@null" after
that, which JSONParser cannot read. Write the short name
(domain: "PositiveReal"), as XMLProducer does.
Do not write a domain that the class sets itself (SimplexParam fixes
UnitInterval): JSONParser rejects a value for an input that is no longer
at its default.
Adds JSONProducerTest: domains written as names, a shared domain written
for every parameter, and JSON round trips keeping real, integer and
simplex domains.
alexeid
approved these changes
Nov 6, 2026
alexeid
left a comment
Member
There was a problem hiding this comment.
Thanks Walter, this fixes #205 cleanly, and the tests cover the cases that matter. I checked that the new tests pass with the fix and fail without it. Two notes for later, not blocking:
isDomainFixedByClassdefault-constructs each class by reflection and treats any exception as "not fixed". That works, but it would quietly misjudge a class whose no-argument constructor fails or has side effects. The underlying oddity isJSONParserrejecting adomainequal to the one the class already set ("Multiple entries for non-list input"); relaxing that in the parser would make this check unnecessary.XMLProducermay have the sameSimplexParamissue (writingdomain="UnitInterval"for a class that fixes it). Worth checking whetherXMLParseraccepts that.
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.
Fixes #205.
JSONProducerwrote each parameter's domain as an object the first time (domain: {spec: "beast.base.spec.domain.PositiveReal"}) and as"@null"after that. As a result, no BEAST 3 model with spec parameters could be written as JSON and read back.Changes (
JSONProducer.inputToJSON)Domaincase: writes the short class name,domain: "PositiveReal", asXMLProducerdoes (XMLProducer.java:1141).SimplexParamfixesUnitIntervalin its constructors, andJSONParserrejects a value for an input that is no longer at its default (Multiple entries for non-list input domain). A domain is skipped when a default-constructed object of the same class already holds it, and it differs from the input's declared default. All other domains are still written explicitly, includingdomain: "Real".Tests
New
beast.base.parser.JSONProducerTest. All 5 tests fail without the fix.domainIsWrittenAsShortNamedomain: "PositiveReal"/"Real"; no domain objects, no"@null"sharedDomainIsWrittenForEveryParameterPositiveRealboth get it (the second used to be"@null")roundTripKeepsDomainsJSONParser.parseFragment→ each parameter has the same domain objectroundTripKeepsIntegerDomainIntVectorParam/NonNegativeIntdomainFixedByTheClassIsNotWrittenSimplexParamwrites no domain and parses back withUnitIntervalValidation
mvn -pl beast-base test) passes: 513 tests, 0 failures, 3 skipped.testUCLNclockmodel from Convert 12 BEAST2 examples to BEAST3 (batch 2); ship SeqGen examples in beast-fx #204, written withJSONProducer, now passesbin/beast -validate. Before the fix it failed withNoSuchMethodException: …PositiveReal.newInstance().