MayaFlux 0.5.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

Extension point — specialize Serializer<T> to handle custom types

Definition at line 158 of file JSONSerializer.hpp.

159 {
160 if constexpr (Reflect::Reflectable<T>) {
161 nlohmann::json j = nlohmann::json::object();
162 std::apply(
163 [&](const auto&... props) {
164 (encode_property(j, val, props), ...);
165 },
166 T::describe());
167 return j;
168 } else if constexpr (Reflect::is_optional_v<T>) {
169 if (!val.has_value()) {
170 return nullptr;
171 }
172 return to_json(*val);
173 } else if constexpr (Reflect::is_vector_v<T>) {
174 auto arr = nlohmann::json::array();
175 for (const auto& item : val) {
176 arr.push_back(to_json(item));
177 }
178 return arr;
179 } else if constexpr (Reflect::is_string_map_v<T>) {
180 nlohmann::json j = nlohmann::json::object();
181 for (const auto& [k, v] : val) {
182 j[k] = to_json(v);
183 }
184 return j;
185 } else if constexpr (std::is_enum_v<T>) {
186 return static_cast<std::underlying_type_t<T>>(val);
187 } else if constexpr (std::is_same_v<T, nlohmann::json>) {
188 return val;
189 } else {
190 /// Extension point — specialize Serializer<T> to handle custom types
191 return Serializer<T>::to_json(val);
192 }
193 }
float k
static void encode_property(nlohmann::json &j, const Class &obj, const Reflect::Property< Class, T > &prop)
static nlohmann::json to_json(const T &val)
static nlohmann::json to_json(const T &val)

References k.