1 module geario.serialization.Common;
2 
3 import std.typecons : Flag;
4 
5 
6 /**
7  * 
8  */
9 struct SerializationOptions {
10     enum Default = SerializationOptions();
11     enum Full = SerializationOptions().includeMeta(true);
12     enum Lite = SerializationOptions().traverseBase(false).ignoreNull(true).Depth(0);
13     enum Normal = SerializationOptions().ignoreNull(true);
14 
15     enum OnlyPublicWithNull = SerializationOptions().onlyPublic(true).traverseBase(false).Depth(0);
16     enum OnlyPublicLite = OnlyPublicWithNull.ignoreNull(true);
17 
18     private bool _onlyPublic = false;
19 
20     private bool _traverseBase = true;
21 
22     private bool _includeMeta = false;
23 
24     private bool _ignoreNull = false;
25 
26     private bool _canThrow = true;
27 
28     private int _depth = -1;
29 
30 /* --------------------------------------------------- properties --------------------------------------------------- */
31 
32     bool onlyPublic() { return _onlyPublic; }
33 
34     SerializationOptions onlyPublic(bool flag) {
35         SerializationOptions r = this;
36         r._onlyPublic = flag;
37         return r;
38     }
39 
40     bool traverseBase() { return _traverseBase; }
41 
42     SerializationOptions traverseBase(bool flag) {
43         SerializationOptions r = this;
44         r._traverseBase = flag;
45         return r;
46     }
47 
48     bool includeMeta() { return _includeMeta; }
49 
50     SerializationOptions includeMeta(bool flag) {
51         SerializationOptions r = this;
52         r._includeMeta = flag;
53         return r;
54     }
55 
56     bool ignoreNull() { return _ignoreNull; }
57 
58     SerializationOptions ignoreNull(bool flag) {
59         SerializationOptions r = this;
60         r._ignoreNull = flag;
61         return r;
62     }
63 
64     bool CanThrow() { return _canThrow; }
65 
66     SerializationOptions CanThrow(bool flag) {
67         SerializationOptions r = this;
68         r._canThrow = flag;
69         return r;
70     }
71 
72     int Depth() { return _depth; }
73 
74     SerializationOptions Depth(int Depth) {
75         SerializationOptions r = this;
76         r._depth = Depth;
77         return r;
78     }
79 }
80 
81 /**
82    Flag indicating whether to traverse the base class.
83 */
84 alias TraverseBase = Flag!"traverseBase";
85 
86 /**
87    Flag indicating whether to allow the public member only.
88 */
89 alias OnlyPublic = Flag!"onlyPublic";
90 
91 /**
92    Flag indicating whether to include the meta data (especially for a class or an interface).
93 */
94 alias IncludeMeta = Flag!"includeMeta";
95 
96 /**
97    Flag indicating whether to ignore the null member.
98 */
99 alias IgnoreNull = Flag!"ignoreNull";
100 
101 
102 /// attributes for json
103 /// https://dzone.com/articles/jackson-annotations-for-json-part-2-serialization
104 
105 /**
106  * Excludes the field from both encoding and decoding.
107  */
108 enum Ignore;
109 
110 deprecated("Using Ignore instead.")
111 alias Exclude = Ignore;
112 
113 /**
114  * Includes this even if it would otherwise be excluded.
115  * If Exclude (or other UDA(@)) and Include are present value will be included.
116  * Can also be used on @property methods to include them. (Be sure both the setter and getter exist!)
117  * If used on a value of a base class value will be included.
118  */
119 enum Include;
120 
121 /**
122  * Excludes the field from decoding, encode only.
123  */
124 enum EncodeOnly;
125 
126 /**
127  * Excludes the field from encoding, decode only.
128  */
129 enum DecodeOnly;