Read path and deserialize into T.
- Returns
- Populated instance, or nullopt on file or parse error. On failure call last_error().
Definition at line 108 of file JSONSerializer.hpp.
109 {
112 std::ifstream file(resolved);
113 if (!file.is_open()) {
114 m_last_error =
"Failed to open for reading: " + resolved;
115 return std::nullopt;
116 }
117 try {
118 auto j = nlohmann::json::parse(file);
121 return out;
122 } catch (const std::exception& e) {
123 m_last_error = std::string(
"read error in ") + resolved +
": " + e.what();
124 return std::nullopt;
125 }
126 }
static std::string resolve_path(const std::string &filepath)
Resolve a filepath against the project source root if not found as-is.
static void from_json(const nlohmann::json &j, T &out)
References MayaFlux::IO::T.
Referenced by MayaFlux::Nexus::StateDecoder::decode(), and MayaFlux::Nexus::StateDecoder::reconstruct().