Skip to content

Commit

Permalink
Augment json_type_traits errors with member name
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Sep 22, 2023
1 parent 8efb52b commit afbfc32
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions include/jsoncons/json_traits_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,59 @@ namespace jsoncons
template <class U>
static void set_optional_json_member(const string_view_type& key, const std::shared_ptr<U>& val, Json& j)
{
if (val) j.try_emplace(key, val);
if (val)
{
try
{
j.try_emplace(key, val);
}
catch (const std::exception& e)
{
JSONCONS_THROW(json_runtime_error<std::runtime_error>(append_key_to_message(e.what(), key)));
}
}
}
template <class U>
static void set_optional_json_member(const string_view_type& key, const std::unique_ptr<U>& val, Json& j)
{
if (val) j.try_emplace(key, val);
if (val)
{
try
{
j.try_emplace(key, val);
}
catch (const std::exception& e)
{
JSONCONS_THROW(json_runtime_error<std::runtime_error>(append_key_to_message(e.what(), key)));
}
}
}
template <class U>
static void set_optional_json_member(const string_view_type& key, const jsoncons::optional<U>& val, Json& j)
{
if (val) j.try_emplace(key, val);
if (val)
{
try
{
j.try_emplace(key, val);
}
catch (const std::exception& e)
{
JSONCONS_THROW(json_runtime_error<std::runtime_error>(append_key_to_message(e.what(), key)));
}
}
}
template <class U>
static void set_optional_json_member(const string_view_type& key, const U& val, Json& j)
{
j.try_emplace(key, val);
try
{
j.try_emplace(key, val);
}
catch (const std::exception& e)
{
JSONCONS_THROW(json_runtime_error<std::runtime_error>(append_key_to_message(e.what(), key)));
}
}
};
}
Expand Down

0 comments on commit afbfc32

Please sign in to comment.