Hi, I think it would be a cool addition to the library if there was a way to specify a conversion method, from a type to basic_json, which would be called by the lib.
Here a sample code of the behaviour I'm thinking about:
// library code
template <typename UserDefinedType>
struct json_traits;
// user code
template <>
struct json_traits<MyType>
{
static basic_json convert(MyType const& val)
{
return {{"first_row", val.first_row}, {"some_value", 42}};
}
};
There could also be a conversion method when get is called
auto obj = json::parse(buffer);
auto val = obj["user_defined_type_value"].get<MyType>();
These are just thoughts for now, but that would remove a LOT of boilerplate in my code.
Plus, this would add some compile-time checks (if the struct is not defined for example)
What's your opinion on that?
Hi, I think it would be a cool addition to the library if there was a way to specify a conversion method, from a type to
basic_json, which would be called by the lib.Here a sample code of the behaviour I'm thinking about:
There could also be a conversion method when
getis calledThese are just thoughts for now, but that would remove a LOT of boilerplate in my code.
Plus, this would add some compile-time checks (if the struct is not defined for example)
What's your opinion on that?