schemagen: keep null elements in arrays with nullable item types #8

Merged
andrew merged 1 commits from weaselbot/weaseljson:weaselbot/issue-5 into main 2026-06-18 20:07:49 +00:00
Member

Closes #5

For array types whose items are nullable ({"type": ["T", "null"]}), the generated builder previously called valueComplete() in cbNull() without appending anything to the owning vector. Null entries were silently dropped, so vector indices no longer matched JSON array indices.

Generate isArrayKind() / appendNull() helpers and have cbNull() append a default-constructed element when the current frame is an array. For std::optional<T> items this appends an empty optional; for std::unique_ptr<T> items it appends a null pointer. Add nullable string/integer array fields to the example schema and test coverage to verify indices are preserved.

Closes #5 For array types whose items are nullable (`{"type": ["T", "null"]}`), the generated builder previously called `valueComplete()` in `cbNull()` without appending anything to the owning vector. Null entries were silently dropped, so vector indices no longer matched JSON array indices. Generate `isArrayKind()` / `appendNull()` helpers and have `cbNull()` append a default-constructed element when the current frame is an array. For `std::optional<T>` items this appends an empty optional; for `std::unique_ptr<T>` items it appends a null pointer. Add nullable string/integer array fields to the example schema and test coverage to verify indices are preserved.
weaselbot added 1 commit 2026-06-18 14:18:22 +00:00
schemagen: keep null elements in arrays with nullable item types
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-arm64, ubuntu-latest-arm64, true) (pull_request) Successful in 51s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-arm64, ubuntu-latest-arm64, false) (pull_request) Successful in 49s
CI / pre-commit (pull_request) Successful in 51s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-amd64, ubuntu-latest-amd64, true) (pull_request) Successful in 1m27s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-amd64, ubuntu-latest-amd64, false) (pull_request) Successful in 1m23s
47f1077100
For array types whose items are nullable ({"type": ["T", "null"]}),
the generated builder previously called valueComplete() on cbNull() without
appending anything to the owning vector. Null entries were silently dropped,
so vector indices no longer matched JSON array indices.

Generate isArrayKind() / appendNull() helpers and have cbNull() append a
default-constructed element when the current frame is an array. For
std::optional<T> items this appends an empty optional; for std::unique_ptr<T>
items it appends a null pointer. Add nullable string/integer array fields to
the example schema and test coverage to verify indices are preserved.

Fixes #5
andrew merged commit 3d9772357d into main 2026-06-18 20:07:49 +00:00
andrew deleted branch weaselbot/issue-5 2026-06-18 20:07:50 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weaselab/weaseljson#8