|
JSON Voorhees
Killer JSON for C++
|
An adapter which can create polymorphic types. More...
#include <jsonv/serialization/polymorphic_adapter.hpp>
Inheritance diagram for jsonv::polymorphic_adapter< TPointer >:
Collaboration diagram for jsonv::polymorphic_adapter< TPointer >:Public Types | |
| using | match_predicate = std::function< bool(extraction_context &, const value &)> |
Public Member Functions | |
| template<typename T > | |
| void | add_subtype (match_predicate pred) |
Add a subtype which can be transformed into TPointer which will be called if the discriminator pred is matched. | |
| template<typename T > | |
| void | add_subtype_keyed (std::string key, value expected_value, keyed_subtype_action action=keyed_subtype_action::none) |
Add a subtype which can be transformed into TPointer which will be called if given a JSON value with kind::object which has a member with key and the provided expected_value. | |
| void | check_null_input (bool on) |
| bool | check_null_input () const |
| void | check_null_output (bool on) |
| } | |
| bool | check_null_output () const |
Public Member Functions inherited from jsonv::adapter_for< T > | |
| virtual const std::type_info & | get_type () const noexcept override |
| virtual std::expected< void, ast_node_type > | extract (extraction_context &context, reader &from, void *into) const override |
| virtual value | to_json (const serialization_context &context, const void *from) const override |
Protected Member Functions | |
| virtual TPointer | create (extraction_context &context, const value &from) const override |
Create an instance of T from the materialised from. | |
| virtual value | to_json (const serialization_context &context, const TPointer &from) const override |
Protected Member Functions inherited from jsonv::value_adapter_for< TPointer > | |
| virtual std::expected< TPointer, ast_node_type > | create (extraction_context &context, reader &from) const final override |
Create an instance of T by reading from. | |
Protected Member Functions inherited from jsonv::adapter_for< T > | |
| virtual value | to_json (const serialization_context &context, const T &from) const =0 |
An adapter which can create polymorphic types.
This allows you to parse JSON directly into a type heirarchy without some middle layer.
| TPointer | Some pointer-like type (likely unique_ptr or shared_ptr) you wish to extract values into. It must support operator*, an explicit conversion to bool, construction with a pointer to a subtype of what it contains and default construction. |
Definition at line 59 of file polymorphic_adapter.hpp.
| using jsonv::polymorphic_adapter< TPointer >::match_predicate = std::function<bool (extraction_context&, const value&)> |
Definition at line 63 of file polymorphic_adapter.hpp.
|
inline |
Add a subtype which can be transformed into TPointer which will be called if the discriminator pred is matched.
Definition at line 73 of file polymorphic_adapter.hpp.
|
inline |
Add a subtype which can be transformed into TPointer which will be called if given a JSON value with kind::object which has a member with key and the provided expected_value.
Definition at line 88 of file polymorphic_adapter.hpp.
Here is the call graph for this function:
|
inline |
Definition at line 116 of file polymorphic_adapter.hpp.
|
inline |
When extracting a C++ value, should kind::null in JSON automatically become a default-constructed TPointer (which is usually the null representation)?
Definition at line 110 of file polymorphic_adapter.hpp.
|
inline |
Definition at line 130 of file polymorphic_adapter.hpp.
|
inline |
}
When converting with to_json, should a null input translate into a kind::null?
Definition at line 124 of file polymorphic_adapter.hpp.
|
inlineoverrideprotectedvirtual |
Create an instance of T from the materialised from.
| extraction_error | if from cannot be converted to a T. |
Implements jsonv::value_adapter_for< TPointer >.
Definition at line 138 of file polymorphic_adapter.hpp.
|
inlineoverrideprotectedvirtual |
Definition at line 161 of file polymorphic_adapter.hpp.