Repository navigation
fix: non-finite floats in JSON I/O under JSON.jl v1 - #20
Merged
Merged
Conversation
…nd v1 JSON.jl v1 defaults to strict RFC 8259: JSON.parse throws on NaN/Infinity/ -Infinity tokens and JSON.json throws when writing non-finite floats, whereas v0.21 parsed those tokens by default and wrote them as null. This broke FUSE act_json/ini_json tests once the ecosystem resolved JSON v1, because IMASdd environments write parameters JSON containing bare NaN tokens (via its AbstractFloat lowering) that jstr2par could no longer parse. - jstr2par: pass allownan=true to JSON.parse (no-op on v0.21, required on v1) so IMAS-convention non-finite tokens parse on both JSON versions - par2jstr: under JSON v1 call JSON.json(data; pretty=indent, allownan=true) since the pre-1.0 compat method JSON.json(data, indent) silently drops keyword arguments and throws on non-finite floats; v0.21 keeps its legacy behavior (non-finite -> null) - add test/test_json.jl covering token parsing, non-finite write/roundtrip, and file I/O on both JSON versions
JSON v1 with allownan=true parses all numbers as Float64 by design (JuliaIO/JSON.jl#397), so Entry{Int} values came back as e.g. 101.0 and setproperty! threw (FUSE ini_json/act_json failures). string_decode_value now coerces scalar floats to the parameter's declared Integer type.
JSON v1 with allownan=true parses every number as Float64 (JuliaIO/JSON.jl#397). The previous fix only coerced Entry{Integer} scalars, so Float32 fields and Union eltypes like Entry{Union{Int64,Vector}} (e.g. act.ActorCoreRadHeatFlux.levels) still threw MethodError on load. string_decode_value now coerces a scalar number to the lone Real member of the declared type, and the vector branch uses convert.(etp, value) so untyped Vector members (eltype Any) no longer hit the missing Any(x) constructor. Adds regression tests covering Int, Float32, and Union{Int,Vector} (scalar and vector) round-trips, mirroring FUSE's ini_json/act_json pattern.
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.
Once an environment resolves JSON.jl v1 (compat widened in #19), SimulationParameters breaks: v1 is strict RFC 8259 by default, so
jstr2parthrows on theNaN/Infinity/-Infinitytokens that IMASdd environments write (the FUSEact_jsonCI failures), andpar2jstrthrows when writing non-finite values.The existing JSON test only round-tripped finite values, so this went uncaught.
jstr2par:JSON.parse(...; allownan=true)— v0.21's default, required on v1par2jstr: on v1 useJSON.json(data; pretty=indent, allownan=true)(thejson(data, indent)compat method silently drops kwargs); v0.21 path unchangedstring_decode_value: coerce scalar floats to declaredIntegertypes — v1'sallownan=trueparses all numbers as Float64 by design (Parsing result of numbers depends onallownanJuliaIO/JSON.jl#397), soEntry{Int}round-trips came back as101.0test/test_json.jlcovers non-finite parse/write/file round-trip and integer round-trip; full suite green on both JSON v0.21.4 and v1.6.1 (Julia 1.11.9)