-
Notifications
You must be signed in to change notification settings - Fork 1
Serialization and deserialization
You can serialize a reflected class to json using the CppReflection::JsonWriter class, the compute method will then convert a Reflectable to a std::string for you like the following:
#include <CppReflection/JsonWriter.h>
#include "MyReflectedClass.h"
using namespace CppReflection;
int main()
{
MyReflectedClass instance;
std::string result = JsonWriter::compute(instance);
return 0;
}
You can deserialize a reflected class from json using the CppReflection::JsonReader class, the load method will then instanciate your reflectable from the given json for you like the following:
#include <CppReflection/JsonReader.h>
#include "MyReflectedClass.h"
using namespace CppReflection;
int main()
{
MyReflectedClass* instance;
instance = JsonReader::load("{\"type\": \"MyReflectedClass\", \"value\": 42}");
return 0;
}
You can serialize a reflected class to yaml using the CppReflection::YamlWriter class, the compute method will then convert a Reflectable to a std::string for you like the following:
#include <CppReflection/YamlWriter.h>
#include "MyReflectedClass.h"
using namespace CppReflection;
int main()
{
MyReflectedClass instance;
std::string result = YamlWriter::compute(instance);
return 0;
}
You can deserialize a reflected class from yaml using the CppReflection::YamlReader class, the load method will then instanciate your reflectable from the given json for you like the following:
#include <CppReflection/YamlReader.h>
#include "MyReflectedClass.h"
using namespace CppReflection;
int main()
{
MyReflectedClass* instance;
instance = YamlReader::load("type: MyReflectedClass\nvalue: 42");
return 0;
}