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.
This commit is contained in:
Juan Carlos Arevalo Baeza (JCAB) 2023-12-08 10:35:09 -08:00
parent e132622794
commit 2eb72beedb

View File

@ -320,7 +320,14 @@ template<typename BasicJsonType, typename EnumType,
inline void to_json(BasicJsonType& j, EnumType e) noexcept inline void to_json(BasicJsonType& j, EnumType e) noexcept
{ {
using underlying_type = typename std::underlying_type<EnumType>::type; using underlying_type = typename std::underlying_type<EnumType>::type;
external_constructor<value_t::number_integer>::construct(j, static_cast<underlying_type>(e)); if (std::is_unsigned<underlying_type>::value)
{
external_constructor<value_t::number_unsigned>::construct(j, static_cast<underlying_type>(e));
}
else
{
external_constructor<value_t::number_integer>::construct(j, static_cast<underlying_type>(e));
}
} }
#endif // JSON_DISABLE_ENUM_SERIALIZATION #endif // JSON_DISABLE_ENUM_SERIALIZATION