json
json copied to clipboard
Does it support std::optional or boost::optional out of the box ?
Hello,
Does it support simple json conversion from std::optional<std::string>
for instance ? When I test I get some errors.
Thanks
Not yet, but it will be most likely added in the future.
I would like to request this as well. Is this something that is being actively looked at, or is it something where a PR would be welcomed?
What would "supporting optional" look like? Can you please give example code (using types from Boost.JSON)?
As I am looking into boost::json
more, I think it might be achievable outside the library by treating null
values as an optional with no value. Perhaps supporting it inside the boost::json
library is not necessary nor desirable.
What would "supporting optional" look like?
Default implementations of value_from
and value_to
for std::optional<T>
.
To be honest, the hardest part of implementing this feature is determining a good trait for what is and isn't an optional. I.e. is checking that the type is std::optional<T>
good enough? I suspect people would expect boost::optional
to be supported too.
Optionals have the member functions .has_value() and .get() That’s probably enough?
Yeah, could work
boost::optional
can be supported on the boost::optional
side. There's no need for JSON to know about all the optionals.
Is there a timeline for this feature?
Most likely before the next Boost release (December)