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:
|
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"
|
??? example "Example 2: Strict deserialization"
|
||||||
@ -73,7 +73,7 @@ inline void from_json(const BasicJsonType& j, type& e);
|
|||||||
Expected output:
|
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:
|
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>
|
template<typename T>
|
||||||
[[noreturn]] inline void json_throw_from_serialize_macro(T&& exception)
|
[[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);
|
throw std::forward<T>(exception);
|
||||||
#else
|
#else
|
||||||
// Forward the exception (even if unused) and abort
|
// Forward the exception (even if unused) and abort
|
||||||
@ -278,7 +278,7 @@ NLOHMANN_JSON_NAMESPACE_END
|
|||||||
}); \
|
}); \
|
||||||
if (it == std::end(m)) { \
|
if (it == std::end(m)) { \
|
||||||
auto value = static_cast<typename std::underlying_type<ENUM_TYPE>::type>(e); \
|
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; \
|
j = it->second; \
|
||||||
} \
|
} \
|
||||||
@ -295,7 +295,7 @@ NLOHMANN_JSON_NAMESPACE_END
|
|||||||
return ej_pair.second == j; \
|
return ej_pair.second == j; \
|
||||||
}); \
|
}); \
|
||||||
if (it == std::end(m)) \
|
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; \
|
e = it->first; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2614,7 +2614,7 @@ namespace detail
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
[[noreturn]] inline void json_throw_from_serialize_macro(T&& exception)
|
[[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);
|
throw std::forward<T>(exception);
|
||||||
#else
|
#else
|
||||||
// Forward the exception (even if unused) and abort
|
// Forward the exception (even if unused) and abort
|
||||||
@ -2644,7 +2644,7 @@ NLOHMANN_JSON_NAMESPACE_END
|
|||||||
}); \
|
}); \
|
||||||
if (it == std::end(m)) { \
|
if (it == std::end(m)) { \
|
||||||
auto value = static_cast<typename std::underlying_type<ENUM_TYPE>::type>(e); \
|
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; \
|
j = it->second; \
|
||||||
} \
|
} \
|
||||||
@ -2661,7 +2661,7 @@ NLOHMANN_JSON_NAMESPACE_END
|
|||||||
return ej_pair.second == j; \
|
return ej_pair.second == j; \
|
||||||
}); \
|
}); \
|
||||||
if (it == std::end(m)) \
|
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; \
|
e = it->first; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1702,7 +1702,7 @@ TEST_CASE("JSON to enum mapping")
|
|||||||
|
|
||||||
// invalid json
|
// invalid json
|
||||||
const json j = "foo";
|
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")
|
SECTION("traditional enum")
|
||||||
@ -1719,7 +1719,7 @@ TEST_CASE("JSON to enum mapping")
|
|||||||
|
|
||||||
// invalid json
|
// invalid json
|
||||||
const json j = "foo";
|
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