Skip to content

(not ready yet) C++ Json Serializer with the possibility to change the default serialization, to REST API style for example. inspired by Cereal.

Notifications You must be signed in to change notification settings

ism-hub/JSerializer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSerializer

Json serializer, the main feature is the possibility to change the default de/serialization by using an external 'mapping file', for example, to create a REST API for your model you can define the small changes needed, in a concise manner, to the default de/serialization in a mapping file (and you will be able to update you model according to the REST specs). Using ArduinoJson and inspired by Cereal.

Code Sample

See the example in the examples folder for a much more detailed example (with the mapping-file feature), because the API will be greatly changed I won't document it all here, this will get updated after the rework.

class Student {
    string _name;
    int _id;
public:
    Student(string name, int id) : _name(name), _id(id) {}
    Student(){}

    template<class Archive>
    void save(Archive& ar) const {
        ar.addProperties(ser::make_nvp("name", _name), ser::make_nvp("id", _id));
    }

    template<class Archive>
    void load(Archive& ar) {
         ar.loadProperties(ser::make_nvp("name", _name), ser::make_nvp("id", _id));
    }
};

int main(){
    Student bob("Bob", 1);
    //creating serialization service
    auto serializationServ = std::make_shared<ser::SerializationService>();
    ser::DefaultSerializationService defaultSerializer(serializationServ);// wrapping the SerializationService for ease of use.

    //default serialization
    std::string serializedDefault = "";
    defaultSerializer.Model2Json(bob, serializedDefault);
    std::cout << serializedDefault << std::endl;//{"name":"Bob","id":1}

    return 0;    
}

About

(not ready yet) C++ Json Serializer with the possibility to change the default serialization, to REST API style for example. inspired by Cereal.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages