Skip to content

Commit 561ebc1

Browse files
committed
Added a test case for #1444
1 parent 2a25b1c commit 561ebc1

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright © 2009-2020 John Sheehan, Andrew Young, Alexey Zimarev and RestSharp community
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using FluentAssertions;
19+
using NUnit.Framework;
20+
using RestSharp.Deserializers;
21+
using RestSharp.Serialization.Json;
22+
23+
namespace RestSharp.Serializers.Tests.IssueCases
24+
{
25+
// https://github.com/restsharp/RestSharp/issues/1444
26+
public class Issue_1444
27+
{
28+
[Test]
29+
public void Complex_type_deserialized_with_SimpleJson()
30+
{
31+
const string json = @"{""panes"":{""filter"":{""records"":[{""data"":{""customernumber"":""10002""}}]}}}";
32+
33+
var actual = (new JsonDeserializer()).Deserialize<FilterBaseModel>(new RestResponse {Content = json});
34+
35+
actual.Panes.Filter.Records.First().Data.Number.Should().Be("10002");
36+
}
37+
38+
class FilterBaseModel
39+
{
40+
public Panes Panes { get; set; }
41+
}
42+
43+
class Panes
44+
{
45+
public Filter Filter { get; set; }
46+
}
47+
48+
class Filter
49+
{
50+
public List<Record> Records { get; set; }
51+
}
52+
53+
public class Record
54+
{
55+
public Data Data { get; set; }
56+
}
57+
58+
public class Data
59+
{
60+
[DeserializeAs(Name = "customernumber")]
61+
public string Number { get; set; }
62+
}
63+
}
64+
}

test/RestSharp.Serializers.Tests/RestSharp.Serializers.Tests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
</PropertyGroup>
55

66
<ItemGroup>
7-
<ProjectReference Include="..\..\src\RestSharp.Serializers.NewtonsoftJson\RestSharp.Serializers.NewtonsoftJson.csproj"/>
8-
<ProjectReference Include="..\..\src\RestSharp.Serializers.SystemTextJson\RestSharp.Serializers.SystemTextJson.csproj"/>
9-
<ProjectReference Include="..\..\src\RestSharp.Serializers.Utf8Json\RestSharp.Serializers.Utf8Json.csproj"/>
10-
<ProjectReference Include="..\..\src\RestSharp\RestSharp.csproj"/>
11-
<ProjectReference Include="..\RestSharp.Tests.Shared\RestSharp.Tests.Shared.csproj"/>
7+
<ProjectReference Include="..\..\src\RestSharp.Serializers.NewtonsoftJson\RestSharp.Serializers.NewtonsoftJson.csproj" />
8+
<ProjectReference Include="..\..\src\RestSharp.Serializers.SystemTextJson\RestSharp.Serializers.SystemTextJson.csproj" />
9+
<ProjectReference Include="..\..\src\RestSharp.Serializers.Utf8Json\RestSharp.Serializers.Utf8Json.csproj" />
10+
<ProjectReference Include="..\..\src\RestSharp\RestSharp.csproj" />
11+
<ProjectReference Include="..\RestSharp.Tests.Shared\RestSharp.Tests.Shared.csproj" />
1212
</ItemGroup>
1313

1414
</Project>

0 commit comments

Comments
 (0)