MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ to_json()

template<typename T >
static nlohmann::json MayaFlux::IO::JSONSerializer::to_json ( const T val)
inlinestaticprivate

Definition at line 141 of file JSONSerializer.hpp.

142 {
143 if constexpr (Reflectable<T>) {
144 nlohmann::json j = nlohmann::json::object();
145 std::apply(
146 [&](const auto&... props) {
147 (encode_property(j, val, props), ...);
148 },
149 T::describe());
150 return j;
151 } else if constexpr (is_optional_v<T>) {
152 if (!val.has_value()) {
153 return nullptr;
154 }
155 return to_json(*val);
156 } else if constexpr (is_vector_v<T>) {
157 auto arr = nlohmann::json::array();
158 for (const auto& item : val) {
159 arr.push_back(to_json(item));
160 }
161 return arr;
162 } else if constexpr (is_string_map_v<T>) {
163 nlohmann::json j = nlohmann::json::object();
164 for (const auto& [k, v] : val) {
165 j[k] = to_json(v);
166 }
167 return j;
168 } else if constexpr (GlmSerializable<T>) {
169 return encode_glm(val);
170 } else if constexpr (std::is_enum_v<T>) {
171 return static_cast<std::underlying_type_t<T>>(val);
172 } else {
173 return val;
174 }
175 }
static nlohmann::json encode_glm(const T &v)
static void encode_property(nlohmann::json &j, const Class &obj, const Property< Class, T > &prop)
static nlohmann::json to_json(const T &val)