Skip to content

glz::patch support for all glz::generic_ types#2387

Merged
stephenberry merged 1 commit intomainfrom
patch-support-for-all-generic-types
Mar 20, 2026
Merged

glz::patch support for all glz::generic_ types#2387
stephenberry merged 1 commit intomainfrom
patch-support-for-all-generic-types

Conversation

@stephenberry
Copy link
Copy Markdown
Owner

@stephenberry stephenberry commented Mar 20, 2026

Add generic_i64 and generic_u64 support to JSON patch functionality

Closes #2385

Summary

The JSON patch module (patch.hpp) was hardcoded to use glz::generic (f64 mode) throughout. This meant that glz::generic_i64 and glz::generic_u64 could not be used with any patch operations, losing integer precision for values beyond what double can represent.

This PR templatizes the entire JSON patch module so that all operations (RFC 6902 patch, RFC 7386 merge patch, and diff) work with any generic_json specialization.

Changes

include/glaze/json/patch.hpp

  • Added is_generic_json type trait and concept to detect any generic_json<Mode, MapType> specialization
  • Templatized patch_op and patch_document into patch_op_t<GenericType> and patch_document_t<GenericType>, with backward-compatible aliases (patch_op = patch_op_t<>, patch_document = patch_document_t<>)
  • Templatized all helper functions (equal, navigate_to_parent, insert_at, remove_at), operation functions (apply_add/remove/replace/move/copy/test), diff, patch, and merge patch functions
  • Fixed the std::visit in diff_impl to use typename GenericType::object_t/array_t instead of hardcoded generic:: types, with a generic else branch that handles all scalar types (double, int64_t, uint64_t, string, bool)
  • Updated the not_generic concept to exclude all generic_json specializations (previously only excluded generic)

tests/json_test/json_patch_test.cpp

  • Added generic_i64_patch_tests suite (9 tests): add, replace with precision preservation, diff/patch round-trip, test, move, merge patch, merge diff, patched (non-mutating), patch_json string convenience
  • Added generic_u64_patch_tests suite (5 tests): add, diff/patch round-trip, test, merge patch, patch_json string convenience

Backward Compatibility

All changes are fully backward compatible. Existing code using patch_op, patch_document, diff(), patch(), merge_patch(), etc. continues to work without modification. All 64 original tests pass unchanged alongside the 14 new tests (78 total, 300 assertions).

@stephenberry stephenberry linked an issue Mar 20, 2026 that may be closed by this pull request
@stephenberry stephenberry merged commit 1c15b86 into main Mar 20, 2026
47 of 48 checks passed
@stephenberry stephenberry deleted the patch-support-for-all-generic-types branch March 20, 2026 14:47
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.

add glz::generic_i64 support to json patch functionality

1 participant