Commit Graph

30 Commits

Author SHA1 Message Date
Niels Lohmann 035c58fc5e Fix CI: use CHECK_THROWS_WITH_AS, the macro that actually exists
CHECK_THROWS_AS_WITH is not a doctest macro; the correct one used throughout
this test suite is CHECK_THROWS_WITH_AS(expr, message, exception_type&), with
the message before the type and the type as a reference. The previous commit
didn't catch this because it only compiled the file standalone with default
settings; this TEST_CASE only compiles under
`#if !JSON_USE_IMPLICIT_CONVERSIONS`, which is why ci_test_noimplicitconversions
was the job that failed. Verified by building and running the test in that
exact configuration (JSON_USE_IMPLICIT_CONVERSIONS=0): 14/14 assertions pass.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-07-08 16:00:46 +02:00
Niels Lohmann b03bec327a Use CHECK_THROWS_AS_WITH for std::optional test assertions
Update the regression tests to use CHECK_THROWS_AS_WITH instead of
CHECK_THROWS_AS to verify both the exception type and the error message.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-07-08 15:16:22 +02:00
Niels Lohmann acca7575ce Fix issue reference in std::optional test comment
Update the comment in the null section test to reference #5246 instead of
placeholder #XXXX, clarifying where the direct-init/copy-init limitation is tracked.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-07-08 15:14:59 +02:00
Niels Lohmann 2f383b80ee Document std::optional<T> direct-init/copy-init limitation with null
Add regression test pinning current behavior (CHECK_THROWS_AS) in the null
section of unit-conversions.cpp with detailed comment explaining the C++
language-level cause (std::optional's own converting constructor wins
overload resolution over basic_json::operator T()).

Add a warning callout in conversions.md documenting that direct construction/
assignment of std::optional<T> from JSON null throws type_error 302, with a
clear workaround (use get<std::optional<T>>() or get_to() instead, which
correctly produce std::nullopt).

This is a limitation at the language level: there is no SFINAE path to
distinguish "called from inside std::optional's own constructor" from "direct
call", so fixing it would require breaking changes to operator ValueType().
A permanent fix belongs in the 4.0 type-strictness redesign (#3453).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-07-08 15:07:50 +02:00
Niels Lohmann 1d7688aef2 optional: use #if instead of #ifndef in test, fixes #3859 (#5183)
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-05-18 22:34:13 +02:00
Caillin Nugent 58cfecf7f7 Serialize enum (#5151)
* Added NLOHNMANN_JSON_SERIALIZE_ENUM_STRICT
- duplicate of NLOHMANN_JSON_SERIALIZE_ENUM

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>

* Added failing tests for NLOHMANN_JSON_SERIALIZE_ENUM_STRICT

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>

* modified NLOHMANN_JSON_SERIALIZE_STRICT to throw

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>

* added documentation and changed readme to include NLOHMANN_JSON_SERIALIZE_ENUM_STRICT

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>

* ran amalgamate

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>

* docs(macros): add page for JSON_SERIALIZE_ENUM_STRICT
- added page to nav
- added links to new page where appropriate

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>

* refactor(macros): make JSON_SERIALIZE_ENUM_STRICT use JSON_THROW
- added templated wrapper function to fix scope error in calling JSON_THROW

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>

* refactor(macros): make NLOHMANN_SERIALIZE_ENUM_STRICT use error code 410
- added error code 410 to docs

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>

* tests(macros): add test for to_json with enum value not mentioned
	       in mapping for NLOHMANN_JSON_SERIALIZE_ENUM_STRICT

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>

* Apply suggestions from code review

Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
Signed-off-by: Caillin Nugent <nugentcaillin@gmail.com>

* fix(macro): prevent compilation error with -Werror and -Wunused-parameter
            with NLOHMANN_JSON_SERIALIZE_ENUM_STRICT
- casted exception to void to avoid warning

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>

* fix(docs): add link to NLOHMANN_SERIALIZE_ENUM_STRICT docs to exception page

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>

* docs(macros): add example of exception throwing for NLOHMANN_JSON_SERIALIZE_ENUM_STRICT

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>

* refactor(macros): add more in-depth error message to NLOHMANN_JSON_SERIALIZE_ENUM_STRICT
- changed error message to follow style of nlohmann/json#4989
- made description of throw wrapper more general
- updated tests and example of exceptions

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>

---------

Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>
Signed-off-by: Caillin Nugent <nugentcaillin@gmail.com>
Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
2026-05-18 20:37:07 +02:00
Niels Lohmann 515d994acb 🦉 adjust year (#5044)
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-01-01 20:00:39 +01:00
Niels Lohmann 54be9b04f0 🦉 update REUSE (#4960) 2025-10-23 06:56:36 +02:00
Niels Lohmann 30d27df61c Fix CI (#4871)
* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 👷 fix CI

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-07-31 20:10:57 +02:00
Niels Lohmann e02de2f971 Update to Doctest 2.4.12 (#4771)
* 🤜 Doctest 2.4.12

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 fix warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-05-15 19:25:27 +02:00
Niels Lohmann 1705bfe914 🔫 set version to 3.12.0 (#4727)
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-04-11 10:41:14 +02:00
risa2000 11aa5f944d Make std::filesystem::path conversion to/from UTF-8 encoded string explicit (#4631)
* Make std::filesystem::path conversion to/from UTF-8 encoded JSON string explicit.

Signed-off-by: Richard Musil <risa2000x@gmail.com>

* Experimental: Changing C++ standard detection logic to accommodate potential corner cases.

Signed-off-by: Richard Musil <risa2000x@gmail.com>

* Drop C++ standard tests for compilers which do not implement required features.

Signed-off-by: Richard Musil <risa2000x@gmail.com>

* Drop C++ standard tests for MSVC versions which do not implement required features.

Signed-off-by: Richard Musil <risa2000x@gmail.com>

---------

Signed-off-by: Richard Musil <risa2000x@gmail.com>
Co-authored-by: Richard Musil <risa2000x@gmail.com>
2025-04-04 10:59:23 +02:00
Niels Lohmann b477d2b95e Suppress clang-analyzer-webkit.NoUncountedMemberChecker (#4701)
* 🎓 suppress clang-analyzer-webkit.NoUncountedMemberChecker

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 suppress invalid misc-const-correctness warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 📡 add Clang 20/21

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 suppress invalid misc-const-correctness warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 suppress invalid misc-const-correctness warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 suppress invalid misc-const-correctness warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 suppress invalid misc-const-correctness warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 suppress invalid misc-const-correctness warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 suppress invalid misc-const-correctness warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 suppress invalid misc-const-correctness warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🎓 suppress invalid misc-const-correctness warnings

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2025-03-29 09:38:45 +01:00
Niels Lohmann f06604fce0 Bump the copyright years (#4606)
* 🦉 bump the copyright years

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🦉 bump the copyright years

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 🦉 bump the copyright years

Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com>
2025-01-19 17:04:17 +01:00
Niels Lohmann 6057b31df7 Overwork astyle call (#4573)
* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* Use ubuntu-latest image to run Valgrind (#4575)

* 🪝 use Clang image to run valgrind

* 🪝 use Clang image to run valgrind

* 🪝 use Clang image to run valgrind

* 🪝 use Ubuntu image to run valgrind

* Use Clang image to run iwyu (#4574)

* 🪝 use Clang image to run iwyu

* 🪝 use Clang image to run iwyu

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🪝 overwork astyle call

* 🚶 format code

* 🤮 clean up
2024-12-29 17:06:03 +01:00
peng-wang-cn 589641b175 Add support of multi-dim C-style array member of struct. (#4262)
* Add support of multi-dim C-style array.

* Support up to 4 dimensional array.

* Suppress clang-tidy checks for C-style arrays
2024-12-10 13:18:21 +01:00
Niels Lohmann 1b9a9d1f21 Update licenses (#4521)
* 🦉 update licenses

* 🦉 update licenses
2024-11-29 17:38:42 +01:00
Niels Lohmann a97041a98f Skip enum tests when JSON_DisableEnumSerialization=ON (#4504)
*  skip enum tests when JSON_DisableEnumSerialization=ON

*  skip enum tests when JSON_DisableEnumSerialization=ON
2024-11-21 17:19:16 +01:00
Fredrik Sandhei 060414037e feat: Rebase feature/optional to develop (#4036)
* 🚧 conversions for std::optional

* 🐏 fix <optional> inclusion

* 🧛 overwork tests

* Use JSON_HAS_CPP_17 only after it has been defined

*  update tests

* 🐏 include right <optional> header

* ♻️ do not include experimental headers

* Add missing #endif after rebase

* Fix failing test

* Only define conversion to std::optional when JSON_USE_IMPLICIT_CONVERSION is disabled.

* missing endif

* Remove Wfloat-equal suppress

* amalgamate

* Move include of optional out of macro_scope; probably does not make sense to be there

* Make clang-tidy happy

* Suppress lint instead of changing to 'contains'

---------

Co-authored-by: Niels Lohmann <mail@nlohmann.me>
Co-authored-by: Markus Palonen <markus.palonen@gmail.com>
2024-11-16 17:19:33 +01:00
Niels Lohmann 1825117e63 Another desperate try to fix the CI (#4489)
* 🎓 fix warning

* 🧛 update actions

* 🎓 fix warning

* 🎓 fix warning

* 🎓 fix warning

* 🧛 update actions

* 🧛 update actions

* 🎓 fix warning

* 🎓 fix warning

* 🧛 update actions

* 🎓 fix warning

* 🧛 update actions

* 🧛 update actions

* 🧛 update actions

* 🎓 fix warning

* 🎓 fix warning

* 🎓 fix warning

* 🎓 fix warning

* 🧛 update actions

* 🧛 update actions

* 🎓 fix warning

* 🧛 update actions

* 🧛 update actions

* 🧛 update actions

* 🧛 update actions

* 🧛 update actions
2024-11-13 10:21:26 +01:00
Niels Lohmann 9cca280a4d JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
Niels Lohmann f56c6e2e30 Update documentation for the next release (#4216) 2023-11-26 15:51:19 +01:00
Raphael Grimm bbe337c3a3 Prevent memory leak when exception is thrown in adl_serializer::to_json (#3901)
Co-authored-by: barcode <barcode@example.com>
2023-03-08 13:43:45 +01:00
Niels Lohmann 58bd97e2b1 Add clang-tools to required tools for ci_static_analysis_clang (#3724)
* 🧛 add clang-tools to required tools for ci_static_analysis_clang

* 🎓 update Clang-Tidy warning selection

* 🎓 fix Clang-Tidy warnings

* 🎓 fix Clang-Tidy warnings

* 🎓 fix Clang-Tidy warnings

* 🎓 fix Clang-Tidy warnings

* 🎓 fix Clang-Tidy warnings

* 🎓 fix Clang-Tidy warnings

* 🎓 fix Clang-Tidy warnings

* 🎓 fix Clang-Tidy warnings

* 🎓 fix Clang-Tidy warnings

* 🎓 fix Clang-Tidy warnings

* 🎓 fix Clang-Tidy warnings (#3738)

*  revert fix

*  revert fix

* 🎓 fix Clang-Tidy warnings (#3739)

Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
2022-09-13 12:58:26 +02:00
Niels Lohmann 9d69186291 🔫 set version to 3.11.2 2022-08-12 15:04:06 +02:00
Niels Lohmann f2020da0dd 🔫 set version to 3.11.1 2022-08-01 23:27:58 +02:00
Niels Lohmann ce0e13ccea 🔫 set version to 3.11.0 2022-07-31 23:19:06 +02:00
Niels Lohmann 527da54dcb Use REUSE framework (#3546)
* 🦉 add licenses

* 👷 add REUSE compliance check

* 📡 add badge for REUSE

Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
2022-07-20 12:38:07 +02:00
Florian Albrechtskirchinger 6b97599a27 Fix C++20/gcc-12 issues (Part 2) (#3446)
* Add C++20 3-way comparison operator and fix broken comparisons

Fixes #3207.
Fixes #3409.

* Fix iterators to meet (more) std::ranges requirements

Fixes #3130.
Related discussion: #3408

* Add note about CMake standard version selection to unit tests

Document how CMake chooses which C++ standard version to use when
building tests.

* Update documentation

* CI: add legacy discarded value comparison

* Fix internal linkage errors when building a module
2022-05-29 13:08:06 +02:00
Niels Lohmann b21c345179 Reorganize directories (#3462)
* 🦃 move files
* 🦃 rename doc folder to docs
* 🦃 rename test folder to tests
2022-05-01 09:41:50 +02:00