Exemplo n.º 1
0
        public static string SerializeObjectToPrettyJson(BaseRequestV2 value)
        {
            StringBuilder sb = new StringBuilder(256);
            StringWriter  sw = new StringWriter(sb, CultureInfo.InvariantCulture);

            var jsonSerializer = JsonSerializer.CreateDefault();

            jsonSerializer.NullValueHandling    = NullValueHandling.Ignore;
            jsonSerializer.DefaultValueHandling = DefaultValueHandling.Ignore;
            jsonSerializer.ContractResolver     = new CamelCasePropertyNamesContractResolver();
            jsonSerializer.Formatting           = Formatting.Indented;

            using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.Formatting  = Formatting.Indented;
                jsonWriter.IndentChar  = '\t';
                jsonWriter.Indentation = 1;

                jsonSerializer.Serialize(jsonWriter, value, typeof(BaseRequestV2));
            }

            string json = sw.ToString();

            return(json.Replace("\r", ""));
        }
Exemplo n.º 2
0
 public static string SerializeToJsonString(BaseRequestV2 request)
 {
     return(JsonConvert.SerializeObject(request, new JsonSerializerSettings()
     {
         Formatting = Formatting.None,
         NullValueHandling = NullValueHandling.Ignore,
         DefaultValueHandling = DefaultValueHandling.Ignore,
         ContractResolver = new CamelCasePropertyNamesContractResolver()
     }));
 }
Exemplo n.º 3
0
 public static StringContent ToJsonString(BaseRequestV2 request)
 {
     return(new StringContent(SerializeObjectToPrettyJson(request), Encoding.UTF8, "application/json"));
 }