MayaFlux 0.4.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 90 of file JSONSerializer.hpp.

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

References MayaFlux::IO::T.