Tag Archives: serialization

header-only non-intrusive json serialization in c++

A while ago I’ve started a convenience, zero error-handling, json serializer wrapper around picojson based on the Boost.Serialization and hiberlite APIs. Today the wrapper got even less intrusive for DTOs that expose their members.

Given a class that cannot be extended in its declaration, but the internals are accessible (following to the Boost.Serialization free function API):

struct Untouchable {
    int value;
};

With a free function defined in the ::picojson::convert namespace,

namespace picojson {
    namespace convert {

        template <class Archive>
        void json(Archive &ar, Untouchable &u) {
            ar &picojson::convert::member("value", u.value);
        }

    }
}

serialization is “again” possible:

Untouchable example = { 42 };
std::string example_string( picojson::convert::to_string(example) );

Untouchable example_deserialized = { 0 };
picojson::convert::from_string( example_string, example_deserialized );
CHECK( example.value == example_deserialized.value );

github.com/d-led/picojson_serializer

lua + pugixml via LuaBridge

Started working on a binding of pugixml for lua: https://github.com/d-led/pugilua

pugixml supports utf-8, so, using icu4lua one could, in principle, have a nice lua-style processing of XML files. The interface is right now kept almost one-to-one to the original. It shows, at least for me, how easy it is to make bindings to C++ using LuaBridge and how easy the usage of pugixml is.