summaryrefslogtreecommitdiffhomepage
path: root/serialize/corrade-string.cpp
blob: 9820e37a2b027aed382c1b1579ad736cf865db68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "corrade-string.hpp"
#include <Corrade/Containers/StringStlView.h>
#include <nlohmann/json.hpp>

using namespace floormat;

namespace nlohmann {

void adl_serializer<String>::to_json(json& j, const String& val)
{
    std::string_view s{val.data(), val.size()};
    using nlohmann::to_json;
    to_json(j, s);
}

void adl_serializer<String>::from_json(const json& j, String& val)
{
    using nlohmann::from_json;
    std::string_view s;
    from_json(j, s);
    val = String{s.data(), s.size()};
}

void adl_serializer<StringView>::to_json(json& j, StringView val)
{
    std::string_view s{val.data(), val.size()};
    using nlohmann::to_json;
    to_json(j, s);
}

void adl_serializer<StringView>::from_json(const json& j, StringView& val)
{
    using nlohmann::from_json;
    std::string_view s;
    from_json(j, s);
    val = StringView{s.data(), s.size()};
}

} // namespace nlohmann