In the 1.x line, there was a container_adapter<T> parial specialization for optional<T> which was meant to
automatically capture optional-like containers.
The idea was that the JSON string { "a": null } would automatically be deserialized to have my_thing::a properly end
up as nullopt.
If you think of optional<T> as a container of either 0 or 1 values, this makes a lot of sense.
However, there are a few important distinctions between a "regular" container (think vector or list) and optional.
How should null be interpreted?
For a classic container, null is considered illegal -- the empty list ([]) is the default (or non-presense).
For optional, null seems a reasonable representation for empty (nullopt), while an empty list [] would be
unfitting.
How should types with null as a valid representation look?
This is a dumb argument...it still applies for the change to.
Since the specialization lived in serialization_optional.hpp, anyone relying on the old behavior will get a
reasonably-accessable compilation error during upgrade.
Those deleting their #include <jsonv/serialization_optional.hpp> without further thought will get a less reasonable
compilation error in the internals of container_adapter.
This specialization is confusing.
In the 1.x line, there was a
container_adapter<T>
parial specialization foroptional<T>
which was meant to automatically captureoptional
-like containers.The idea was that the JSON string
{ "a": null }
would automatically be deserialized to havemy_thing::a
properly end up asnullopt
. If you think ofoptional<T>
as a container of either 0 or 1 values, this makes a lot of sense. However, there are a few important distinctions between a "regular" container (thinkvector
orlist
) andoptional
.null
be interpreted? For a classic container,null
is considered illegal -- the empty list ([]
) is the default (or non-presense). Foroptional
,null
seems a reasonable representation for empty (nullopt
), while an empty list[]
would be unfitting.null
as a valid representation look? This is a dumb argument...it still applies for the change to.Since the specialization lived in
serialization_optional.hpp
, anyone relying on the old behavior will get a reasonably-accessable compilation error during upgrade. Those deleting their#include <jsonv/serialization_optional.hpp>
without further thought will get a less reasonable compilation error in the internals ofcontainer_adapter
.