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
    public class SaturnJsonSerializer : ISerializer
    {
        private readonly JsonSerializer _serializer;

        public SaturnJsonSerializer()
        {
            ContentType = "application/json";
            _serializer = new JsonSerializer
            {
                MissingMemberHandling = MissingMemberHandling.Ignore,
                NullValueHandling = NullValueHandling.Include,
                DefaultValueHandling = DefaultValueHandling.Include
            };
        }

        public SaturnJsonSerializer(JsonSerializer serializer)
        {
            ContentType = "application/json";
            _serializer = serializer;
        }

        public string Serialize(object obj)
        {
            using (var stringWriter = new StringWriter())
            {
                using (var jsonTextWriter = new JsonTextWriter(stringWriter))
                {
                    jsonTextWriter.Formatting = Formatting.Indented;
                    jsonTextWriter.QuoteChar = '"';

                    _serializer.Serialize(jsonTextWriter, obj);

                    var result = stringWriter.ToString();
                    return result;
                }
            }
        }

        public string DateFormat { get; set; }

        public string RootElement { get; set; }

        public string Namespace { get; set; }

        public string ContentType { get; set; }
    }
 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
public class SaturnRequest : RestRequest
    {
        #region Constructors
        public SaturnRequest()
        {
            IntializeJsonSerializer();
        }

        public SaturnRequest(Method method) : base(method)
        {
            IntializeJsonSerializer();
        }

        public SaturnRequest(string resource) : base(resource)
        {
            IntializeJsonSerializer();
        }

        public SaturnRequest(string resource, Method method) : base(resource, method)
        {
            IntializeJsonSerializer();
        }

        public SaturnRequest(Uri resource) : base(resource)
        {
            IntializeJsonSerializer();
        }

        public SaturnRequest(Uri resource, Method method) : base(resource, method)
        {
            IntializeJsonSerializer();
        }

        #endregion

        #region Methods
        protected void IntializeJsonSerializer()
        {
            JsonSerializer = new SaturnJsonSerializer();
        }
        #endregion
    }

##usage

1
2
var request = new SaturnRequest("/api",Method.POST);
request.AddJsonBody(obj);