From 26394b4e6749a41c3633db040e0987500a5f7013 Mon Sep 17 00:00:00 2001 From: Silverside Date: Mon, 21 Sep 2026 03:32:07 -0500 Subject: [PATCH] json: Fixed json enum handling (#28518) * Fixed json enum handling Added common_json_value handling for enum values. Added tests/test-json.cpp to cover testing of some aspects of common_json. * Removed tests as requested. * Applied recommended style and simplification Simplified by delegating enum constructor to the constructor of the underlying type Matched style of surrounding templating code --- common/json.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/json.h b/common/json.h index f3ad4edee8..95b6d6f212 100644 --- a/common/json.h +++ b/common/json.h @@ -82,6 +82,9 @@ struct common_json_value { // note: a nested pair {"a", "b"} does not build, use common_json::array({"a", "b"}) for an array common_json_value(std::initializer_list items); + template ::value, int>::type = 0> + common_json_value(T val) : common_json_value((typename std::underlying_type::type) val) {} + template ::value && !std::is_same::value, int>::type = 0> common_json_value(T val) : type(std::is_signed::value ? VAL_INT : VAL_UINT) { if (std::is_signed::value) { @@ -111,6 +114,7 @@ struct common_json_item { // the types common_json_value holds on its own // anything else reaches its common_json ctor and recurses forever template struct common_json_is_value : std::integral_constant::value || std::is_arithmetic::value || std::is_same::value || std::is_same::value ||