From 2eb72beedb8ff6526978de38c8b286b887f78b21 Mon Sep 17 00:00:00 2001 From: "Juan Carlos Arevalo Baeza (JCAB)" Date: Fri, 8 Dec 2023 10:35:09 -0800 Subject: [PATCH] Fix the issue in the relevant `to_json` overload. Select the correct json type depending on the signedness of the enum's underlying type. This fixes the new checks in the unit test. --- include/nlohmann/detail/conversions/to_json.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index e39b7797d..8a8610821 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp @@ -320,7 +320,14 @@ template::type; - external_constructor::construct(j, static_cast(e)); + if (std::is_unsigned::value) + { + external_constructor::construct(j, static_cast(e)); + } + else + { + external_constructor::construct(j, static_cast(e)); + } } #endif // JSON_DISABLE_ENUM_SERIALIZATION