Skip to content

Add opt-in <rfl/nlohmann.hpp> adapter for nlohmann::json - #69

Open
clockblocker wants to merge 3 commits into
mainfrom
nlohmann-adapter
Open

clockblocker wants to merge 3 commits into
mainfrom
nlohmann-adapter

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds an opt-in, header-only nlohmann::json adapter (<rfl/nlohmann.hpp>) supporting direct rfl::nlohmann::read<T, Ps...> / rfl::nlohmann::write<Ps...>, lossless nlohmann::basic_json fields inside reflected structs across formats, and opt-in nlohmann::adl_serializer integration (<rfl/nlohmann/adl_serializer.hpp>).

Reconciled Review Fixes (N1–N8)

  • N1 (Packaging): Wired REFLECTCPP_NLOHMANN into REFLECTCPP_ALL_FORMATS, vcpkg.json (nlohmann feature), and conanfile.py (with_nlohmann).
  • N2 (Version floor): Enforced nlohmann_json >= 3.11.3 in CMakeLists.txt, reflectcpp-config.cmake.in, and Reader.hpp static_assert.
  • N3 (Cross-format & BasicJson fidelity): Added is_nlohmann_reader_v / is_nlohmann_writer_v, lossless cross-basic_json conversion, and guarded uint64_t and YAML quoted strings (Tag() == "!") in read_from_generic_reader.
  • N4 (Binary & Vectorstring): Supported rfl::Vectorstring and nlohmann::binary_t <-> Bytestring / Base64.
  • N5 (Opt-in ADL serializer): Extracted <rfl/nlohmann/adl_serializer.hpp> guarded by __cpp_exceptions, dropped 2-arg from_json (preserving Validator and const-field support), and throw BasicJsonType::other_error::create(501, ...).
  • N6–N8 (Conventions, perf, docs, tests): Renamed detail -> internal, used emplace + reserve in Writer, used BasicJson::string_t in Reader::find, added docs/content/supported_formats/nlohmann.md, and verified all 3 CMake matrix configs + standalone header compilation under -Wall -Werror.

Verification

  • REFLECTCPP_JSON=ON -DREFLECTCPP_NLOHMANN=ON: 591/591 passed
  • REFLECTCPP_JSON=OFF -DREFLECTCPP_NLOHMANN=ON: 8/8 passed
  • REFLECTCPP_NLOHMANN=OFF: 582/582 passed

- N1: Add vcpkg nlohmann feature, conan with_nlohmann option, and wire
  REFLECTCPP_NLOHMANN into REFLECTCPP_ALL_FORMATS and vcpkg features.
- N2: Enforce nlohmann_json >= 3.11.3 in CMake, package config, and
  Reader.hpp static_assert.
- N3: Add is_nlohmann_reader_v/is_nlohmann_writer_v and lossless
  cross-BasicJson conversion; guard uint64_t and YAML quoted strings
  (Tag() == "!") in read_from_generic_reader.
- N4: Support rfl::Vectorstring and nlohmann binary_t <-> Bytestring/Base64.
- N5: Extract opt-in nlohmann/adl_serializer.hpp guarded by
  __cpp_exceptions, drop 2-arg from_json for Validator/const-field support,
  and throw BasicJsonType::other_error::create(501, ...).
- N6-N8: Rename detail -> internal, use emplace + reserve in Writer,
  use BasicJson::string_t in Reader::find, add docs and expanded tests.
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.

1 participant