summaryrefslogtreecommitdiffhomepage
path: root/serialize/string.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'serialize/string.cpp')
-rw-r--r--serialize/string.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/serialize/string.cpp b/serialize/string.cpp
new file mode 100644
index 00000000..0c0fa74e
--- /dev/null
+++ b/serialize/string.cpp
@@ -0,0 +1,39 @@
+#include "string.hpp"
+#include <Corrade/Containers/String.h>
+#include <string_view>
+#include <nlohmann/json.hpp>
+
+using String = Corrade::Containers::String;
+using StringView = Corrade::Containers::StringView;
+
+namespace nlohmann {
+
+void adl_serializer<String>::to_json(json& j, const String& val)
+{
+ using nlohmann::to_json;
+ to_json(j, std::string_view { val.cbegin(), val.cend() });
+}
+
+void adl_serializer<String>::from_json(const json& j, String& val)
+{
+ using nlohmann::from_json;
+ std::string_view str;
+ from_json(j, str);
+ val = { str.cbegin(), str.size() };
+}
+
+void adl_serializer<StringView>::to_json(json& j, const StringView& val)
+{
+ using nlohmann::to_json;
+ to_json(j, std::string_view { val.cbegin(), val.cend() });
+}
+
+void adl_serializer<StringView>::from_json(const json& j, StringView& val)
+{
+ using nlohmann::from_json;
+ std::string_view str;
+ from_json(j, str);
+ val = { str.cbegin(), str.size() };
+}
+
+} // namespace nlohmann