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 143 of file JSONSerializer.hpp.

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