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

◆ from_json()

template<typename T >
static void MayaFlux::IO::JSONSerializer::from_json ( const nlohmann::json &  j,
T &  out 
)
inlinestaticprivate

Definition at line 224 of file JSONSerializer.hpp.

225 {
226 if constexpr (Reflect::Reflectable<T>) {
227 if (!j.is_object()) {
228 throw nlohmann::json::type_error::create(302, "expected object for Reflectable type", &j);
229 }
230 std::apply(
231 [&](const auto&... props) {
232 (decode_property(j, out, props), ...);
233 },
234 T::describe());
235 } else if constexpr (Reflect::is_optional_v<T>) {
236 using Inner = typename Reflect::is_optional<T>::inner;
237 if (j.is_null()) {
238 out = std::nullopt;
239 } else {
240 Inner inner {};
241 from_json(j, inner);
242 out = std::move(inner);
243 }
244 } else if constexpr (Reflect::is_vector_v<T>) {
245 using V = typename Reflect::is_vector<T>::element;
246 if (!j.is_array())
247 throw nlohmann::json::type_error::create(302, "expected array", &j);
248 out.clear();
249 out.reserve(j.size());
250 for (const auto& item : j) {
251 V element {};
252 from_json(item, element);
253 out.push_back(std::move(element));
254 }
255
256 } else if constexpr (Reflect::is_string_map_v<T>) {
257 using V = typename Reflect::is_string_map<T>::element;
258 if (!j.is_object())
259 throw nlohmann::json::type_error::create(302, "expected object for map", &j);
260 out.clear();
261 for (const auto& [k, v] : j.items()) {
262 V val {};
263 from_json(v, val);
264 out.emplace(k, std::move(val));
265 }
266 } else if constexpr (std::is_enum_v<T>) {
267 out = static_cast<T>(j.get<std::underlying_type_t<T>>());
268
269 } else if constexpr (std::is_same_v<T, nlohmann::json>) {
270 out = j;
271
272 } else {
274 }
275 }
std::vector< float > * out
static void from_json(const nlohmann::json &j, T &out)
static void decode_property(const nlohmann::json &j, Class &obj, const Reflect::Property< Class, T > &prop)
static void from_json(const nlohmann::json &j, T &out)

References out, MayaFlux::IO::T, and MayaFlux::IO::V.