template specialization not deteced for third party type nested to STL containers #5374
|
Hello everyone, I'm using nlohmann json(which I love btw !) for a C++ project and I'm struggling to find the "good" way to convert a third party type when it is nested inside a STL container. namespace nlohmann {
template <>
struct adl_serializer<wxString> {
static void to_json(json& j, const wxString& str) {
j = str.utf8_string();
}
static void from_json(const json& j, wxString& str) {
str = wxString::FromUTF8(j.get<std::string>());
}
};
...But when used inside template <>
struct adl_serializer<std::vector<wxString>> {
static void to_json(json& j, const std::vector<wxString>& str) {
std::ranges::for_each(str,
[&](const wxString& s)
{
j.push_back(s.utf8_string());
}
);
}
static void from_json(const json& j, std::vector<wxString>& str) {
std::ranges::for_each(j,
[&](const std::string& s)
{
str.push_back(wxString::FromUTF8(s));
}
);
}
};
};Am I doing something wrong ? To my understanding, I should have only wrote the first specialization. Thank you for your help, |
Replies: 3 comments
|
Hello Mohammad, Thank you for your reply. I do think there is a visibility problem with my header containing the specialization because I did everything like you mentioned and still, it looks like the specialization is not "visible" when performing the conversion to |
|
So... I created a new header file with ONLY the nlohmann json specialization and.... it worked. Thank you, |

So... I created a new header file with ONLY the nlohmann json specialization and.... it worked.
Thank you,