|
| 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 | +} |
0 commit comments