Override conversion for STL-like user types #3699
-
Suppose i have the following struct struct foo
{
std::string tag;
std::vector<int> data;
...
iterator begin() { return this->data.begin(); }
iterator end() { return this->data.end(); }
// so i can use for (const auto& p : foo), etc
}; Now if i try to define a custom conversion to json by void from_json(const json& j, foo& p)
{
p.tag = j.at("tag").get<std::string>();
p.data = j.at("data").get<std::vector<int>>();
...
} It would not work, since the existence of iterator functions would made the library use the default serialization as if |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
A related issue is very high on my to-do list. I'll take your use case into account when I get to it. You can probably work around the issue by implementing a custom serializer that forwards to the default serializer for all types but |
Beta Was this translation helpful? Give feedback.
A related issue is very high on my to-do list. I'll take your use case into account when I get to it.
You can probably work around the issue by implementing a custom serializer that forwards to the default serializer for all types but
foo
.