DotNameLib
Loading...
Searching...
No Matches
IJsonSerializer.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <filesystem>
5#include <nlohmann/json.hpp>
6#include <string>
7
8namespace dotnamecpp::utils {
15 public:
16 virtual ~IJsonSerializer() = default;
17
24 [[nodiscard]]
26 loadFromFile(const std::filesystem::path &filePath) const = 0;
27
36 [[nodiscard]]
37 virtual Result<void, JsonError> saveToFile(const std::filesystem::path &filePath,
38 const nlohmann::json &jsonData,
39 int indent = 2) const = 0;
40
47 [[nodiscard]]
48 virtual Result<nlohmann::json, JsonError> parse(const std::string &jsonString) const = 0;
49
57 [[nodiscard]]
58 virtual Result<std::string, JsonError> toString(const nlohmann::json &jsonData,
59 int indent = 2) const = 0;
60 };
61
62} // namespace dotnamecpp::utils
Interface for JSON serialization and parsing.
Definition IJsonSerializer.hpp:14
virtual Result< nlohmann::json, JsonError > loadFromFile(const std::filesystem::path &filePath) const =0
Load JSON from file.
virtual Result< nlohmann::json, JsonError > parse(const std::string &jsonString) const =0
Parse JSON from string.
virtual Result< void, JsonError > saveToFile(const std::filesystem::path &filePath, const nlohmann::json &jsonData, int indent=2) const =0
Save JSON to file.
virtual Result< std::string, JsonError > toString(const nlohmann::json &jsonData, int indent=2) const =0
Convert JSON to string.
Definition UtilsError.hpp:93
Definition DirectoryManager.cpp:5