-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
JsonResponseDeserializer.cs
25 lines (23 loc) · 1.01 KB
/
JsonResponseDeserializer.cs
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
using Newtonsoft.Json;
using System.Net.Http;
namespace RestEase
{
/// <summary>
/// Default implementation of IResponseDeserializer, using Json.NET
/// </summary>
public class JsonResponseDeserializer : ResponseDeserializer
{
/// <summary>
/// Gets or sets the serializer settings to pass to JsonConvert.DeserializeObject{T}
/// </summary>
public JsonSerializerSettings? JsonSerializerSettings { get; set; }
/// <inheritdoc/>
public override T Deserialize<T>(string? content, HttpResponseMessage response, ResponseDeserializerInfo info)
{
// TODO: Figure out how best to handle nullables here. I don't think we can change the signature to return T?
// without breaking backwards compat... In the meantime, this worked before json.net changed their nullable
// annotations, so ignore the issue for now
return JsonConvert.DeserializeObject<T>(content!, this.JsonSerializerSettings)!;
}
}
}