Serialize C++ object hierarchies into JSON documents and vice versa almost as conveniently as Java objects using Jackson.
Mapping C++ object hierarchies and containers to JSON documents. There are a couple of C++ JSON parsers/generators out there, mature and proven. I will not attempt to write a better one. Instead, JXXON relies on existing ones.
JXXON does not expose any details of the encapsulated JSON parsers/generators to clients. Neither explicitly, nor via transitive inclusion.
Providing a common interface base class, which all serializable classes are to implement.
Lacking such an interface, object mapper consumer classes supposed to handle more than one type would be forced to a non-polymorphic design, using non-virtual template member functions, or using member overloads. In any case, sacrificing all object oriented runtime flexibility.
Throwing exceptions, when there is a null value somewhere in JSON input, is probably the least helpful thing to do. Null values are valid JSON, even when they occur as array elements.
C++ standard containers should feel like first class citizens in JSON. Based on a little bit of wrapping.
Best practice rather than strictly a design goal. A templatized test suite helps boosting code and branch coverage to amazing levels.
#include "JXXON/Serializable.h"
#include <string>
struct SampleObject : public JXXON::Serializable
{
// Deserializing constructor
SampleObject(const JXXON::Json &json) :
property(json.get<decltype(property)>("property_name")),
{
}
// Serializing virtual function
virtual JXXON::Json toJson() const override
{
JXXON::Json json;
json.set("property_name", property);
return json;
}
// Non-nullable field.
std::string property;
};
- Template templates with parameter packs
- Smart pointers
- Lambda expressions
- Range loops
JXXON is using Polymorphic decorators >= 1.2.0 to extend C++11 standard containers and to add serializability.
Processing of JSON documents is delegated to either JsonCpp >= 1.6.0 or Poco >= 1.7.4, depending on your choice when building the JXXON library.
Free Software, licensed under the Boost Software License.