Skip to content

docs: migrate examples from JSON3.jl to JSON.jl v1#1250

Open
s-celles wants to merge 1 commit intoJuliaWeb:masterfrom
s-celles:101-migrate-json3-to-json-v1
Open

docs: migrate examples from JSON3.jl to JSON.jl v1#1250
s-celles wants to merge 1 commit intoJuliaWeb:masterfrom
s-celles:101-migrate-json3-to-json-v1

Conversation

@s-celles
Copy link
Copy Markdown
Contributor

Closes #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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

is JSON3 deprecated?

1 participant