diff --git a/test/src/unit-udt.cpp b/test/src/unit-udt.cpp index 60b83957..10e8b71a 100644 --- a/test/src/unit-udt.cpp +++ b/test/src/unit-udt.cpp @@ -394,15 +394,22 @@ namespace nlohmann template <> struct adl_serializer> { - static void to_json(json& j, std::vector const&) + using type = std::vector; + static void to_json(json& j, type const&) { j = "hijacked!"; } - static void from_json(json const&, std::vector& opt) + static void from_json(json const&, type& opt) { opt = {42.0, 42.0, 42.0}; } + + // preferred version + static type from_json(json const&) + { + return {4.0, 5.0, 6.0}; + } }; } @@ -411,7 +418,8 @@ TEST_CASE("even supported types can be specialized", "[udt]") json j = std::vector {1.0, 2.0, 3.0}; CHECK(j.dump() == R"("hijacked!")"); auto f = j.get>(); - CHECK((f == std::vector{42.0, 42.0, 42.0})); + // the single argument from_json method is preferred + CHECK((f == std::vector{4.0, 5.0, 6.0})); } namespace nlohmann