Skip to content

Instantly share code, notes, and snippets.

@emanuelefirmani
Last active May 8, 2020 06:12
Show Gist options
  • Save emanuelefirmani/54065e631312d30da61386ebcd96306a to your computer and use it in GitHub Desktop.
Save emanuelefirmani/54065e631312d30da61386ebcd96306a to your computer and use it in GitHub Desktop.
RestSharp JsonDeserializer is not correctly deserializing the response. Here is a comparison with Newtonsoft
using System.Linq;
using RestSharp;
using RestSharp.Serialization.Json;
using Xunit;
namespace JsonSerialization
{
public class UnitTest1
{
private const string json = @"{""panes"":{""filter"":{""records"":[{""data"":{""customernumber"":""10002""}}]}}}";
[Fact]
public void newtonsoft()
{
var actual = Newtonsoft.Json.JsonConvert.DeserializeObject<FilterBaseModel>(json);
Assert.Equal("10002", actual.Panes.Filter.Records.First().Data.Number);
}
[Fact]
public void restsharp()
{
var actual = (new JsonDeserializer()).Deserialize<FilterBaseModel>(new RestResponse {Content = json});
Assert.Equal("10002", actual.Panes.Filter.Records.First().Data.Number);
}
}
}
@emanuelefirmani
Copy link
Author

image

@alexeyzimarev
Copy link

Where is your FilterBaseModel model?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment