Skip to content

Commit e25fc04

Browse files
committed
address review comments
Signed-off-by: Harinath Nampally <[email protected]>
1 parent 0cda972 commit e25fc04

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

docs/mkdocs/docs/api/macros/nlohmann_json_serialize_enum _strict.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ inline void from_json(const BasicJsonType& j, type& e);
5959
Expected output:
6060
6161
```
62-
[json.exception.type_error.302] can't serialize - enum value 3 out of range
62+
[json.exception.type_error.302] serialization failed: enum value 3 is out of range
6363
```
6464
6565
??? example "Example 2: Strict deserialization"
@@ -73,7 +73,7 @@ inline void from_json(const BasicJsonType& j, type& e);
7373
Expected output:
7474
7575
```
76-
[json.exception.type_error.302] can't deserialize - invalid json value : "yellow"
76+
[json.exception.type_error.302] deserialization failed: invalid JSON value "yellow"
7777
```
7878
7979
Both examples demonstrate:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[json.exception.type_error.302] can't serialize - enum value 3 out of range
1+
[json.exception.type_error.302] serialization failed: enum value 3 is out of range

include/nlohmann/detail/macro_scope.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ namespace detail
248248
template<typename T>
249249
[[noreturn]] inline void json_throw_from_serialize_macro(T&& exception)
250250
{
251-
#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) || defined(EXCEPTIONS)
251+
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
252252
throw std::forward<T>(exception);
253253
#else
254254
// Forward the exception (even if unused) and abort
@@ -278,7 +278,7 @@ NLOHMANN_JSON_NAMESPACE_END
278278
}); \
279279
if (it == std::end(m)) { \
280280
auto value = static_cast<typename std::underlying_type<ENUM_TYPE>::type>(e); \
281-
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)); \
281+
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)); \
282282
} \
283283
j = it->second; \
284284
} \
@@ -295,7 +295,7 @@ NLOHMANN_JSON_NAMESPACE_END
295295
return ej_pair.second == j; \
296296
}); \
297297
if (it == std::end(m)) \
298-
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)); \
298+
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("deserialization failed: invalid JSON value ", j.dump()), &j)); \
299299
e = it->first; \
300300
}
301301

single_include/nlohmann/json.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,7 +2614,7 @@ namespace detail
26142614
template<typename T>
26152615
[[noreturn]] inline void json_throw_from_serialize_macro(T&& exception)
26162616
{
2617-
#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) || defined(EXCEPTIONS)
2617+
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
26182618
throw std::forward<T>(exception);
26192619
#else
26202620
// Forward the exception (even if unused) and abort
@@ -2644,7 +2644,7 @@ NLOHMANN_JSON_NAMESPACE_END
26442644
}); \
26452645
if (it == std::end(m)) { \
26462646
auto value = static_cast<typename std::underlying_type<ENUM_TYPE>::type>(e); \
2647-
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)); \
2647+
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)); \
26482648
} \
26492649
j = it->second; \
26502650
} \
@@ -2661,7 +2661,7 @@ NLOHMANN_JSON_NAMESPACE_END
26612661
return ej_pair.second == j; \
26622662
}); \
26632663
if (it == std::end(m)) \
2664-
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)); \
2664+
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("deserialization failed: invalid JSON value ", j.dump()), &j)); \
26652665
e = it->first; \
26662666
}
26672667

tests/src/unit-conversions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ TEST_CASE("JSON to enum mapping")
17021702

17031703
// invalid json
17041704
const json j = "foo";
1705-
CHECK_THROWS_WITH_AS(j.template get<cards_strict>(), "[json.exception.type_error.302] can't deserialize - invalid json value : \"foo\"", json::type_error);
1705+
CHECK_THROWS_WITH_AS(j.template get<cards_strict>(), "[json.exception.type_error.302] deserialization failed: invalid JSON value \"foo\"", json::type_error);
17061706
}
17071707

17081708
SECTION("traditional enum")
@@ -1719,7 +1719,7 @@ TEST_CASE("JSON to enum mapping")
17191719

17201720
// invalid json
17211721
const json j = "foo";
1722-
CHECK_THROWS_WITH_AS(j.template get<TaskStateStrict>(), "[json.exception.type_error.302] can't deserialize - invalid json value : \"foo\"", json::type_error);
1722+
CHECK_THROWS_WITH_AS(j.template get<TaskStateStrict>(), "[json.exception.type_error.302] deserialization failed: invalid JSON value \"foo\"", json::type_error);
17231723
}
17241724
}
17251725

0 commit comments

Comments
 (0)