docs: migrate examples from JSON3.jl to JSON.jl v1#1250
Open
s-celles wants to merge 1 commit intoJuliaWeb:masterfrom
Open
docs: migrate examples from JSON3.jl to JSON.jl v1#1250s-celles wants to merge 1 commit intoJuliaWeb:masterfrom
s-celles wants to merge 1 commit intoJuliaWeb:masterfrom
Conversation
Closes JuliaWeb#1249. JSON3.jl is deprecated. Migrate the two bundled REST-server examples to JSON.jl v1 per the official migration guide: - JSON3.read(body, T) -> JSON.parse(body, T) - JSON3.write(x) -> JSON.json(x) - StructTypes.StructType(::Type{T}) = StructTypes.Mutable() -> removed (JSON.jl v1 auto-detects struct fields) Add an explicit positional inner constructor `Animal(id, userId, type, name)` to both examples so JSON.jl v1's StructUtils can construct the struct from its parsed fields. The existing zero-arg `Animal()` constructor is preserved because the in-script client section still uses `x = Animal(); x.type = ...`. Add a regression test (test/examples_no_json3.jl) that walks docs/examples/ and asserts no .jl file references the JSON3 or StructTypes modules. This test was written first, observed to fail on the unmigrated tree (the TDD red step required by the project constitution), and turned green by the migration. Two pre-existing example bugs were fixed along the way because they blocked end-to-end validation of the migration on Julia >= 1.12: - The leading `"""..."""` description in both files used to be parsed as a docstring attached to the following `using` statement, which Julia 1.12 rejects with "cannot document the following expression". Convert both to `#=...=#` block comments. - cors_server.jl's intentional bad-path probe (`HTTP.get(".../badpath")`) raised on the 404 because HTTP.jl raises on error statuses by default. Pass `status_exception=false` so the example exercises the cors404 handler as intended. Both fixes are documented under `### Fixed` in CHANGELOG.md alongside the main `### Changed` migration entry. No public API of HTTP.jl changes. Project.toml [deps] is unchanged; JSON.jl remains a test/extras dependency only.
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 #1249.
JSON3.jl is deprecated. Migrate the two bundled REST-server examples to JSON.jl v1 per the official migration guide:
(JSON.jl v1 auto-detects struct fields)
Add an explicit positional inner constructor
Animal(id, userId, type, name)to both examples so JSON.jl v1's StructUtils can construct the struct from its parsed fields. The existing zero-argAnimal()constructor is preserved because the in-script client section still usesx = Animal(); x.type = ....Add a regression test (test/examples_no_json3.jl) that walks docs/examples/ and asserts no .jl file references the JSON3 or StructTypes modules. This test was written first, observed to fail on the unmigrated tree (the TDD red step required by the project constitution), and turned green by the migration.
Two pre-existing example bugs were fixed along the way because they blocked end-to-end validation of the migration on Julia >= 1.12:
"""..."""description in both files used to be parsed as a docstring attached to the followingusingstatement, which Julia 1.12 rejects with "cannot document the following expression". Convert both to#=...=#block comments.HTTP.get(".../badpath")) raised on the 404 because HTTP.jl raises on error statuses by default. Passstatus_exception=falseso the example exercises the cors404 handler as intended.Both fixes are documented under
### Fixedin CHANGELOG.md alongside the main### Changedmigration entry.No public API of HTTP.jl changes. Project.toml [deps] is unchanged; JSON.jl remains a test/extras dependency only.