-
Notifications
You must be signed in to change notification settings - Fork 0
/
safe_from_string.cpp
71 lines (63 loc) · 1.33 KB
/
safe_from_string.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <sstream>
#include <iostream>
#include "../safe_json.hpp"
namespace jss = ztu::json::safe;
namespace my_object_builder {
using namespace jss::literals;
using my_default_object_t = object<
set<"boolean", true_B>{},
set<"integer", -1_I>{},
set<"unsigned", 6_U>{},
set<"floating", 3.5_N>{},
set<"string", "test"_S>{},
set<"enum",
enumeration<"two",
"one", "two", "three"
>{}
>{},
set<"array",
array<1_I,
1_I, 2_I, 3_I
>{}
>{},
set<"variant",
variant<"one",
holds<"one",
set<"b", true_B>{}
>{},
holds<"two",
set<"i", 1_I>{}
>{},
holds<"three",
set<"f", 1.0_N>{}
>{}
>{}
>{}
>;
}
constexpr my_object_builder::my_default_object_t my_default_object{};
int main() {
auto is = std::stringstream(
"{\n"
" \"boolean\": true,\n"
" \"integer\": -3.33,\n"
" \"unsigned\": -345,\n"
" \"floating\": 2.0,\n"
" \"string\": \"test\",\n"
" \"enum\": \"one\",\n"
" \"numbers\": \"not-a-number\",\n"
" \"array\": {\n"
" \"test\": \"some-string\"\n"
" },\n"
" \"variant\": {\n"
" \"_type\": \"two\",\n"
" \"i\": 2\n"
" }\n"
"}"
);
auto parser = jss::parser(is);
auto value = parser.parse<my_default_object>();
auto serializer = jss::serializer(std::cout);
serializer.serialize<my_default_object>(value);
std::cout << std::endl;
}