json icon indicating copy to clipboard operation
json copied to clipboard

Does it support std::optional or boost::optional out of the box ?

Open vricosti opened this issue 2 years ago • 11 comments

Hello,

Does it support simple json conversion from std::optional<std::string> for instance ? When I test I get some errors. Thanks

vricosti avatar Feb 09 '22 12:02 vricosti

Not yet, but it will be most likely added in the future.

grisumbras avatar Feb 09 '22 13:02 grisumbras

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?

toonetown avatar May 09 '22 20:05 toonetown

What would "supporting optional" look like? Can you please give example code (using types from Boost.JSON)?

vinniefalco avatar May 09 '22 22:05 vinniefalco

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.

toonetown avatar May 09 '22 23:05 toonetown

What would "supporting optional" look like?

Default implementations of value_from and value_to for std::optional<T>.

pdimov avatar Aug 03 '22 07:08 pdimov

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.

grisumbras avatar Aug 03 '22 16:08 grisumbras

Optionals have the member functions .has_value() and .get() That’s probably enough?

madmongo1 avatar Aug 03 '22 16:08 madmongo1

Yeah, could work

grisumbras avatar Aug 03 '22 16:08 grisumbras

boost::optional can be supported on the boost::optional side. There's no need for JSON to know about all the optionals.

pdimov avatar Aug 03 '22 16:08 pdimov

Is there a timeline for this feature?

NexusHero avatar Aug 10 '22 11:08 NexusHero

Most likely before the next Boost release (December)

grisumbras avatar Aug 11 '22 05:08 grisumbras