replace constructor by from/to_json: array_t

- tweaked a bit how `get<container<json>>` is handled
- added a from_json overload for forward list
This commit is contained in:
Théo DELRIEU 2017-01-08 16:17:47 +01:00
parent 6d427acdde
commit c847e0eea2
4 changed files with 249 additions and 171 deletions

View file

@ -1004,6 +1004,8 @@ TEST_CASE("value conversion")
CHECK_THROWS_AS((json().get<std::vector<json>>()), std::logic_error);
CHECK_THROWS_AS((json().get<std::list<json>>()), std::logic_error);
// does type really must be an array? or it rather must not be null?
// that's what I thought when other test like this one broke
CHECK_THROWS_WITH((json().get<std::list<int>>()), "type must be array, but is null");
CHECK_THROWS_WITH((json().get<std::vector<int>>()), "type must be array, but is null");
CHECK_THROWS_WITH((json().get<std::vector<json>>()), "type must be array, but is null");

View file

@ -391,19 +391,19 @@ TEST_CASE("adl_serializer specialization", "[udt]")
namespace nlohmann
{
// this might work in the future, not in the scope of this PR though
// we have to make this very clear in the doc
template <typename T>
struct adl_serializer<std::vector<T>>
{
static void to_json(json& j, std::vector<T> const& opt)
{
}
static void from_json(json const& j, std::vector<T>& opt)
{
}
};
// TODO provide a real example, since this works now :)
// template <typename T>
// struct adl_serializer<std::vector<T>>
// {
// static void to_json(json& j, std::vector<T> const& opt)
// {
//
// }
//
// static void from_json(json const& j, std::vector<T>& opt)
// {
// }
// };
}
TEST_CASE("current supported types are preferred over specializations", "[udt]")