Last active
August 1, 2021 17:55
-
-
Save jessenich/bff366f188603769b222e4400994e4a2 to your computer and use it in GitHub Desktop.
To use Newtonson JSON Converter with RestSharp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using RestSharp.Deserializers; | |
| using RestSharp.Serializers; | |
| namespace RestSharp.Serialization | |
| { | |
| public interface IRestSerializer : ISerializer, IDeserializer | |
| { | |
| string[] SupportedContentTypes { get; } | |
| DataFormat DataFormat { get; } | |
| string Serialize(Parameter parameter); | |
| } | |
| } | |
| public class JsonNetSerializer : IRestSerializer | |
| { | |
| public string Serialize(object obj) => | |
| JsonConvert.SerializeObject(obj); | |
| public string Serialize(Parameter bodyParameter) => | |
| JsonConvert.SerializeObject(bodyParameter.Value); | |
| public T Deserialize<T>(IRestResponse response) => | |
| JsonConvert.DeserializeObject<T>(response.Content); | |
| public string[] SupportedContentTypes { get; } = | |
| { | |
| "application/json", "text/json", "text/x-json", "text/javascript", "*+json" | |
| }; | |
| public string ContentType { get; set; } = "application/json"; | |
| public DataFormat DataFormat { get; } = DataFormat.Json; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment