address review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
This commit is contained in:
parent
0cda972377
commit
e25fc042ff
@ -59,7 +59,7 @@ inline void from_json(const BasicJsonType& j, type& e);
|
||||
Expected output:
|
||||
|
||||
```
|
||||
[json.exception.type_error.302] can't serialize - enum value 3 out of range
|
||||
[json.exception.type_error.302] serialization failed: enum value 3 is out of range
|
||||
```
|
||||
|
||||
??? example "Example 2: Strict deserialization"
|
||||
@ -73,7 +73,7 @@ inline void from_json(const BasicJsonType& j, type& e);
|
||||
Expected output:
|
||||
|
||||
```
|
||||
[json.exception.type_error.302] can't deserialize - invalid json value : "yellow"
|
||||
[json.exception.type_error.302] deserialization failed: invalid JSON value "yellow"
|
||||
```
|
||||
|
||||
Both examples demonstrate:
|
||||
|
||||
@ -1 +1 @@
|
||||
[json.exception.type_error.302] can't serialize - enum value 3 out of range
|
||||
[json.exception.type_error.302] serialization failed: enum value 3 is out of range
|
||||
|
||||
@ -248,7 +248,7 @@ namespace detail
|
||||
template<typename T>
|
||||
[[noreturn]] inline void json_throw_from_serialize_macro(T&& exception)
|
||||
{
|
||||
#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) || defined(EXCEPTIONS)
|
||||
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
|
||||
throw std::forward<T>(exception);
|
||||
#else
|
||||
// Forward the exception (even if unused) and abort
|
||||
@ -278,7 +278,7 @@ NLOHMANN_JSON_NAMESPACE_END
|
||||
}); \
|
||||
if (it == std::end(m)) { \
|
||||
auto value = static_cast<typename std::underlying_type<ENUM_TYPE>::type>(e); \
|
||||
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't serialize - enum value ", std::to_string(value), " out of range"), &j)); \
|
||||
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("serialization failed: enum value ", std::to_string(value), " is out of range"), &j)); \
|
||||
} \
|
||||
j = it->second; \
|
||||
} \
|
||||
@ -295,7 +295,7 @@ NLOHMANN_JSON_NAMESPACE_END
|
||||
return ej_pair.second == j; \
|
||||
}); \
|
||||
if (it == std::end(m)) \
|
||||
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \
|
||||
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("deserialization failed: invalid JSON value ", j.dump()), &j)); \
|
||||
e = it->first; \
|
||||
}
|
||||
|
||||
|
||||
@ -2614,7 +2614,7 @@ namespace detail
|
||||
template<typename T>
|
||||
[[noreturn]] inline void json_throw_from_serialize_macro(T&& exception)
|
||||
{
|
||||
#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) || defined(EXCEPTIONS)
|
||||
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
|
||||
throw std::forward<T>(exception);
|
||||
#else
|
||||
// Forward the exception (even if unused) and abort
|
||||
@ -2644,7 +2644,7 @@ NLOHMANN_JSON_NAMESPACE_END
|
||||
}); \
|
||||
if (it == std::end(m)) { \
|
||||
auto value = static_cast<typename std::underlying_type<ENUM_TYPE>::type>(e); \
|
||||
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't serialize - enum value ", std::to_string(value), " out of range"), &j)); \
|
||||
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("serialization failed: enum value ", std::to_string(value), " is out of range"), &j)); \
|
||||
} \
|
||||
j = it->second; \
|
||||
} \
|
||||
@ -2661,7 +2661,7 @@ NLOHMANN_JSON_NAMESPACE_END
|
||||
return ej_pair.second == j; \
|
||||
}); \
|
||||
if (it == std::end(m)) \
|
||||
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \
|
||||
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("deserialization failed: invalid JSON value ", j.dump()), &j)); \
|
||||
e = it->first; \
|
||||
}
|
||||
|
||||
|
||||
@ -1702,7 +1702,7 @@ TEST_CASE("JSON to enum mapping")
|
||||
|
||||
// invalid json
|
||||
const json j = "foo";
|
||||
CHECK_THROWS_WITH_AS(j.template get<cards_strict>(), "[json.exception.type_error.302] can't deserialize - invalid json value : \"foo\"", json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j.template get<cards_strict>(), "[json.exception.type_error.302] deserialization failed: invalid JSON value \"foo\"", json::type_error);
|
||||
}
|
||||
|
||||
SECTION("traditional enum")
|
||||
@ -1719,7 +1719,7 @@ TEST_CASE("JSON to enum mapping")
|
||||
|
||||
// invalid json
|
||||
const json j = "foo";
|
||||
CHECK_THROWS_WITH_AS(j.template get<TaskStateStrict>(), "[json.exception.type_error.302] can't deserialize - invalid json value : \"foo\"", json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j.template get<TaskStateStrict>(), "[json.exception.type_error.302] deserialization failed: invalid JSON value \"foo\"", json::type_error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user