28 #include <boost/optional.hpp>
29 #include <rapidjson/document.h>
32 namespace serializer {
34 inline void to_json(
const std::string& x, rapidjson::Value& value,
35 rapidjson::Document::AllocatorType& allocator) {
36 value.SetString(rapidjson::StringRef(x.c_str(), x.size()), allocator);
39 inline void to_json(int32_t x, rapidjson::Value& value,
40 rapidjson::Document::AllocatorType&) {
44 inline void to_json(int64_t x, rapidjson::Value& value,
45 rapidjson::Document::AllocatorType&) {
49 inline void to_json(
double x, rapidjson::Value& value,
50 rapidjson::Document::AllocatorType&) {
53 inline void to_json(
bool x, rapidjson::Value& value,
54 rapidjson::Document::AllocatorType&) {
58 inline void to_json(
const std::shared_ptr<std::vector<unsigned char>>& x,
59 rapidjson::Value& value,
60 rapidjson::Document::AllocatorType& allocator) {
61 value.SetString(
reinterpret_cast<char*
>(x->data()),
62 static_cast<rapidjson::SizeType
>(x->size()), allocator);
66 inline void to_json(
const boost::optional<T>& x, rapidjson::Value& value,
67 rapidjson::Document::AllocatorType& allocator) {
69 to_json(x.get(), value, allocator);
76 inline void to_json(
const std::map<std::string, T>& x, rapidjson::Value& value,
77 rapidjson::Document::AllocatorType& allocator) {
79 for (
auto itr = x.begin(); itr != x.end(); ++itr) {
80 const auto& key = itr->first;
81 rapidjson::Value item_value;
82 to_json(itr->second, item_value, allocator);
83 value.AddMember(rapidjson::StringRef(key.c_str(), key.size()),
84 std::move(item_value), allocator);
89 inline void to_json(
const std::vector<T>& x, rapidjson::Value& value,
90 rapidjson::Document::AllocatorType& allocator) {
92 for (
typename std::vector<T>::const_iterator itr = x.begin(); itr != x.end();
94 rapidjson::Value item_value;
95 to_json(*itr, item_value, allocator);
96 value.PushBack(std::move(item_value), allocator);
100 template <
typename T>
101 inline void serialize(
const std::string& key,
const T& x,
102 rapidjson::Value& value,
103 rapidjson::Document::AllocatorType& allocator) {
104 rapidjson::Value key_value;
105 to_json(key, key_value, allocator);
106 rapidjson::Value item_value;
107 to_json(x, item_value, allocator);
108 if (!item_value.IsNull()) {
109 value.AddMember(std::move(key_value), std::move(item_value), allocator);
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24