template<typename T>
class JsonSerializable< T >
Interface for Json serialization functionality using CRTP.
- Template Parameters
-
T | The serializable type and inheriting class |
Inheriting this class provides json serialization capabilities for reading/writing json objects/strings/files. This class should be inherited with public inheritance in order for it to be of use. This class uses CRTP (Curiously Recurring Template Pattern) https://en.cppreference.com/w/cpp/language/crtp} in order to have static methods which act as constructors for the derived (inheriting) class. Inheriting this class will require the override implementation of three protected methods to serialize, deserialize, and check identity.
Requirements on the templated class T:
- Must be default constructible.
- Must inherit this class.
The implemntation of serialize/deserialize should write/read the members you wish to serialize to/from aurostd::JSON:object. Implementation of the third ID method should return a string ID for the class, typically the class name. See MockSerializableMember and MockSerializableMain for example implementations.
Note: It may be useful to use a macro to define a comma separated list of the members the class will serialize. If defined, this macro should have the name JSON_<class ID/class name>_MEMBERS. This macro would then be passed to the AST_JSON_SETTER
and AST_JSON_GETTER
macros to generate assignments for deserialization and a dictionary/map for serialization, respectively. Again, see MockSerializableMain for an example. These macros will only work if the type is supported for cast conversion by aurostd::JSON::object class, which includes many numeric, list-like, and dictionary-like types as well as others inheriting JsonSerializable.
- Authors
- 20250108 | Scott Thiel - created
20250315 | Scott Thiel - slightly modify interface for clearer contract on inheriters
Definition at line 47 of file aurostd_xserialization.h.