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 backend and interop adapter (<rfl/nlohmann.hpp>), enabling direct rfl::nlohmann::read / write, lossless nlohmann::basic_json fields inside reflected structs across formats, and opt-in nlohmann::adl_serializer integration.

Example

#include <rfl/nlohmann.hpp>

struct Envelope {
  std::string id;
  nlohmann::json payload;
};

nlohmann::json j = rfl::nlohmann::write(env);
auto parsed = rfl::nlohmann::read<Envelope>(j).value();

Key details

  • Opt-in via REFLECTCPP_NLOHMANN (wired into REFLECTCPP_ALL_FORMATS, vcpkg.json, and conanfile.py; requires nlohmann_json >= 3.11.3).
  • Supports nlohmann::basic_json specializations, rfl::Vectorstring, and nlohmann::binary_t ↔ Bytestring/Base64, with guarded uint64_t and YAML quoted-string handling across formats.
  • Opt-in <rfl/nlohmann/adl_serializer.hpp> (guarded by __cpp_exceptions) uses from_json returning T directly so rfl::Validator and const fields work cleanly.
  • Documented in docs/content/supported_formats/nlohmann.md.

AI-authored.

- 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.
clockblocker added a commit that referenced this pull request Nov 29, 2026
…lohmann.hpp>)

- Rebase #69 cleanly onto origin/main (290bdb2).
- Deduplicate reserve_array, reserve_object, and emplace_field into
  rfl::nlohmann::internal in Writer.hpp and use insert_or_assign in
  Writer::emplace_in_object (eliminating default-null + overwrite).
- Fix Reader integer range checks to use width-agnostic IntT/UIntT
  common-type bounds checks instead of hardcoded int64_t/uint64_t casts,
  and add a 32-bit custom basic_json bounds test.
- Drop unnecessary (void) casts in Parser.hpp and document the msgpack-c
  v6 ABI layout constant (0x02).
- Keep REFLECTCPP_NLOHMANN opt-in (OFF by default) with zero optional
  dependency leaks in CMake, reflectcpp-config.cmake.in, vcpkg, or Conan.
clockblocker added a commit that referenced this pull request Nov 29, 2026
…lohmann.hpp>)

- Rebase #69 cleanly onto origin/main (290bdb2).
- Deduplicate reserve_array, reserve_object, and emplace_field into
  rfl::nlohmann::internal in Writer.hpp and use insert_or_assign in
  Writer::emplace_in_object (eliminating default-null + overwrite).
- Fix Reader integer range checks to use width-agnostic IntT/UIntT
  common-type bounds checks instead of hardcoded int64_t/uint64_t casts,
  and add a 32-bit custom basic_json bounds test.
- Drop unnecessary (void) casts in Parser.hpp and document the msgpack-c
  v6 ABI layout constant (0x02).
- Keep REFLECTCPP_NLOHMANN opt-in (OFF by default) with zero optional
  dependency leaks in CMake, reflectcpp-config.cmake.in, vcpkg, or Conan.
clockblocker added a commit that referenced this pull request Nov 29, 2026
…lohmann.hpp>)

- Rebase #69 cleanly onto origin/main (290bdb2).
- Deduplicate reserve_array, reserve_object, and emplace_field into
  rfl::nlohmann::internal in Writer.hpp and use insert_or_assign in
  Writer::emplace_in_object (eliminating default-null + overwrite).
- Fix Reader integer range checks to use width-agnostic IntT/UIntT
  common-type bounds checks instead of hardcoded int64_t/uint64_t casts,
  and add a 32-bit custom basic_json bounds test.
- Drop unnecessary (void) casts in Parser.hpp and document the msgpack-c
  v6 ABI layout constant (0x02).
- Keep REFLECTCPP_NLOHMANN opt-in (OFF by default) with zero optional
  dependency leaks in CMake, reflectcpp-config.cmake.in, vcpkg, or Conan.
clockblocker added a commit that referenced this pull request Nov 29, 2026
…lohmann.hpp>)

- Rebase #69 cleanly onto origin/main (290bdb2).
- Deduplicate reserve_array, reserve_object, and emplace_field into
  rfl::nlohmann::internal in Writer.hpp and use insert_or_assign in
  Writer::emplace_in_object (eliminating default-null + overwrite).
- Fix Reader integer range checks to use width-agnostic IntT/UIntT
  common-type bounds checks instead of hardcoded int64_t/uint64_t casts,
  and add a 32-bit custom basic_json bounds test.
- Drop unnecessary (void) casts in Parser.hpp and document the msgpack-c
  v6 ABI layout constant (0x02).
- Keep REFLECTCPP_NLOHMANN opt-in (OFF by default) with zero optional
  dependency leaks in CMake, reflectcpp-config.cmake.in, vcpkg, or Conan.
clockblocker added a commit that referenced this pull request Nov 29, 2026
…lohmann.hpp>)

- Rebase #69 cleanly onto origin/main (290bdb2).
- Deduplicate reserve_array, reserve_object, and emplace_field into
  rfl::nlohmann::internal in Writer.hpp and use insert_or_assign in
  Writer::emplace_in_object (eliminating default-null + overwrite).
- Fix Reader integer range checks to use width-agnostic IntT/UIntT
  common-type bounds checks instead of hardcoded int64_t/uint64_t casts,
  and add a 32-bit custom basic_json bounds test.
- Drop unnecessary (void) casts in Parser.hpp and document the msgpack-c
  v6 ABI layout constant (0x02).
- Keep REFLECTCPP_NLOHMANN opt-in (OFF by default) with zero optional
  dependency leaks in CMake, reflectcpp-config.cmake.in, vcpkg, or Conan.
clockblocker added a commit that referenced this pull request Nov 30, 2026
…lohmann.hpp>)

- Rebase #69 cleanly onto origin/main (290bdb2).
- Deduplicate reserve_array, reserve_object, and emplace_field into
  rfl::nlohmann::internal in Writer.hpp and use insert_or_assign in
  Writer::emplace_in_object (eliminating default-null + overwrite).
- Fix Reader integer range checks to use width-agnostic IntT/UIntT
  common-type bounds checks instead of hardcoded int64_t/uint64_t casts,
  and add a 32-bit custom basic_json bounds test.
- Drop unnecessary (void) casts in Parser.hpp and document the msgpack-c
  v6 ABI layout constant (0x02).
- Keep REFLECTCPP_NLOHMANN opt-in (OFF by default) with zero optional
  dependency leaks in CMake, reflectcpp-config.cmake.in, vcpkg, or Conan.
clockblocker added a commit that referenced this pull request Nov 30, 2026
…lohmann.hpp>)

- Rebase #69 cleanly onto origin/main (290bdb2).
- Deduplicate reserve_array, reserve_object, and emplace_field into
  rfl::nlohmann::internal in Writer.hpp and use insert_or_assign in
  Writer::emplace_in_object (eliminating default-null + overwrite).
- Fix Reader integer range checks to use width-agnostic IntT/UIntT
  common-type bounds checks instead of hardcoded int64_t/uint64_t casts,
  and add a 32-bit custom basic_json bounds test.
- Drop unnecessary (void) casts in Parser.hpp and document the msgpack-c
  v6 ABI layout constant (0x02).
- Keep REFLECTCPP_NLOHMANN opt-in (OFF by default) with zero optional
  dependency leaks in CMake, reflectcpp-config.cmake.in, vcpkg, or Conan.
clockblocker added a commit that referenced this pull request Nov 30, 2026
…lohmann.hpp>)

- Rebase #69 cleanly onto origin/main (290bdb2).
- Deduplicate reserve_array, reserve_object, and emplace_field into
  rfl::nlohmann::internal in Writer.hpp and use insert_or_assign in
  Writer::emplace_in_object (eliminating default-null + overwrite).
- Fix Reader integer range checks to use width-agnostic IntT/UIntT
  common-type bounds checks instead of hardcoded int64_t/uint64_t casts,
  and add a 32-bit custom basic_json bounds test.
- Drop unnecessary (void) casts in Parser.hpp and document the msgpack-c
  v6 ABI layout constant (0x02).
- Keep REFLECTCPP_NLOHMANN opt-in (OFF by default) with zero optional
  dependency leaks in CMake, reflectcpp-config.cmake.in, vcpkg, or Conan.
clockblocker added a commit that referenced this pull request Dec 1, 2026
…lohmann.hpp>)

- Rebase #69 cleanly onto origin/main (290bdb2).
- Deduplicate reserve_array, reserve_object, and emplace_field into
  rfl::nlohmann::internal in Writer.hpp and use insert_or_assign in
  Writer::emplace_in_object (eliminating default-null + overwrite).
- Fix Reader integer range checks to use width-agnostic IntT/UIntT
  common-type bounds checks instead of hardcoded int64_t/uint64_t casts,
  and add a 32-bit custom basic_json bounds test.
- Drop unnecessary (void) casts in Parser.hpp and document the msgpack-c
  v6 ABI layout constant (0x02).
- Keep REFLECTCPP_NLOHMANN opt-in (OFF by default) with zero optional
  dependency leaks in CMake, reflectcpp-config.cmake.in, vcpkg, or Conan.
clockblocker added a commit that referenced this pull request Dec 1, 2026
…lohmann.hpp>)

- Rebase #69 cleanly onto origin/main (290bdb2).
- Deduplicate reserve_array, reserve_object, and emplace_field into
  rfl::nlohmann::internal in Writer.hpp and use insert_or_assign in
  Writer::emplace_in_object (eliminating default-null + overwrite).
- Fix Reader integer range checks to use width-agnostic IntT/UIntT
  common-type bounds checks instead of hardcoded int64_t/uint64_t casts,
  and add a 32-bit custom basic_json bounds test.
- Drop unnecessary (void) casts in Parser.hpp and document the msgpack-c
  v6 ABI layout constant (0x02).
- Keep REFLECTCPP_NLOHMANN opt-in (OFF by default) with zero optional
  dependency leaks in CMake, reflectcpp-config.cmake.in, vcpkg, or Conan.
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