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

◆ decode()

template<typename T >
std::optional< T > MayaFlux::IO::JSONSerializer::decode ( const std::string &  str)
inline

Parse str and deserialize into T.

Returns
Populated instance, or nullopt on any parse or structural error. On failure call last_error().

Definition at line 87 of file JSONSerializer.hpp.

88 {
89 m_last_error.clear();
90 try {
91 auto j = nlohmann::json::parse(str);
92 T out {};
93 from_json(j, out);
94 return out;
95 } catch (const std::exception& e) {
96 m_last_error = std::string("decode error: ") + e.what();
97 return std::nullopt;
98 }
99 }
static void from_json(const nlohmann::json &j, T &out)

References MayaFlux::IO::T.