Skip to content

Commit 8164c56

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # .github/workflows/build-master.yml
2 parents 92ad955 + 5ff81a6 commit 8164c56

File tree

6 files changed

+108
-16
lines changed

6 files changed

+108
-16
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,36 @@ Read the docs: [Official Site][1]
2121

2222
Find RestSharp on Twitter: [@RestSharp][2]
2323

24+
## Contributors
25+
26+
### Code Contributors
27+
28+
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
29+
<a href="https://github.com/restsharp/RestSharp/graphs/contributors"><img src="https://opencollective.com/RestSharp/contributors.svg?width=890&button=false" /></a>
30+
31+
### Financial Contributors
32+
33+
Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/RestSharp/contribute)]
34+
35+
#### Individuals
36+
37+
<a href="https://opencollective.com/RestSharp"><img src="https://opencollective.com/RestSharp/individuals.svg?width=890"></a>
38+
39+
#### Organizations
40+
41+
Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/RestSharp/contribute)]
42+
43+
<a href="https://opencollective.com/RestSharp/organization/0/website"><img src="https://opencollective.com/RestSharp/organization/0/avatar.svg"></a>
44+
<a href="https://opencollective.com/RestSharp/organization/1/website"><img src="https://opencollective.com/RestSharp/organization/1/avatar.svg"></a>
45+
<a href="https://opencollective.com/RestSharp/organization/2/website"><img src="https://opencollective.com/RestSharp/organization/2/avatar.svg"></a>
46+
<a href="https://opencollective.com/RestSharp/organization/3/website"><img src="https://opencollective.com/RestSharp/organization/3/avatar.svg"></a>
47+
<a href="https://opencollective.com/RestSharp/organization/4/website"><img src="https://opencollective.com/RestSharp/organization/4/avatar.svg"></a>
48+
<a href="https://opencollective.com/RestSharp/organization/5/website"><img src="https://opencollective.com/RestSharp/organization/5/avatar.svg"></a>
49+
<a href="https://opencollective.com/RestSharp/organization/6/website"><img src="https://opencollective.com/RestSharp/organization/6/avatar.svg"></a>
50+
<a href="https://opencollective.com/RestSharp/organization/7/website"><img src="https://opencollective.com/RestSharp/organization/7/avatar.svg"></a>
51+
<a href="https://opencollective.com/RestSharp/organization/8/website"><img src="https://opencollective.com/RestSharp/organization/8/avatar.svg"></a>
52+
<a href="https://opencollective.com/RestSharp/organization/9/website"><img src="https://opencollective.com/RestSharp/organization/9/avatar.svg"></a>
53+
2454
### License: Apache License 2.0
2555

2656
[1]: https://restsharp.dev

docs/get-help/faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ code back and some content, but the typed `Data` property is empty.
5050

5151
In that case, you probably got deserialization issues. By default, RestSharp will just return an empty (`null`) result in the `Data` property.
5252
Deserialization errors can be also populated to the error response. To do that,
53-
set the `client.FailOnDeserialization` property to `true`.
53+
set the `client.FailOnDeserializationError` property to `true`.
5454

5555
It is also possible to force RestSharp to throw an exception.
5656

docs/usage/exceptions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ in favour of giving you the error as a property.
1212

1313
| Property | Behavior |
1414
| ------------- |-------------|
15-
| `FailOnDeserialization` | Changes the default behavior when failed deserialization results in a successful response with an empty `Data` property of the response. Setting this property to `true` will tell RestSharp to consider failed deserialization as an error and set the `ResponseStatus` to `Error` accordingly. |
16-
| `ThrowOnDeserialization` | Changes the default behavior when failed deserialization results in empty `Data` property of the response. Setting this property to `true` will tell RestSharp to throw when deserialization fails. |
15+
| `FailOnDeserializationError` | Changes the default behavior when failed deserialization results in a successful response with an empty `Data` property of the response. Setting this property to `true` will tell RestSharp to consider failed deserialization as an error and set the `ResponseStatus` to `Error` accordingly. |
16+
| `ThrowOnDeserializationError` | Changes the default behavior when failed deserialization results in empty `Data` property of the response. Setting this property to `true` will tell RestSharp to throw when deserialization fails. |
1717
| `ThrowOnAnyError` | Setting this property to `true` changes the default behavior and forces RestSharp to throw if any errors occurs when making a request or during deserialization. |
1818

1919
Those properties are available for the `IRestClient` instance and will be used for all request made with that instance.

src/RestSharp/RestRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public RestRequest(string resource, Method method, DataFormat dataFormat) : this
8888
}
8989

9090
static IEnumerable<NameValuePair> ParseQuery(string query)
91-
=> query.Split('&')
91+
=> query.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries)
9292
.Select(
9393
x =>
9494
{

src/RestSharp/Serializers/Xml/XmlSerializer.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,14 @@ void Map(XContainer root, object obj)
189189
}
190190
else if (rawValue is IList items)
191191
{
192-
var itemTypeName = "";
193-
194192
foreach (var item in items)
195193
{
196-
if (itemTypeName == "")
197-
{
198-
var type = item.GetType();
199-
var setting = type.GetAttribute<SerializeAsAttribute>();
194+
var type = item.GetType();
195+
var setting = type.GetAttribute<SerializeAsAttribute>();
200196

201-
itemTypeName = setting != null && setting.Name.HasValue()
202-
? setting.Name
203-
: type.Name;
204-
}
197+
var itemTypeName = setting != null && setting.Name.HasValue()
198+
? setting.Name
199+
: type.Name;
205200

206201
var instance = new XElement(itemTypeName.AsNamespaced(Namespace));
207202

test/RestSharp.Tests/XmlSerializerTests.cs

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,36 @@ public XmlSerializerTests()
1818
Thread.CurrentThread.CurrentUICulture = CultureInfo.InstalledUICulture;
1919
}
2020

21+
[Test]
22+
public void Can_serialize_a_list_of_items_with_interface_type()
23+
{
24+
var items = new NamedItems
25+
{
26+
Items = new List<INamed>
27+
{
28+
new Person
29+
{
30+
Name = "Foo",
31+
Age = 50,
32+
Price = 19.95m,
33+
StartDate = new DateTime(2009, 12, 18, 10, 2, 23),
34+
Items = new List<Item>
35+
{
36+
new Item {Name = "One", Value = 1},
37+
}
38+
},
39+
new Item {Name = "Two", Value = 2},
40+
new Item {Name = "Three", Value = 3}
41+
}
42+
};
43+
44+
var xml = new XmlSerializer();
45+
var doc = xml.Serialize(items);
46+
var expected = GetNamedItemsXDoc(CultureInfo.InvariantCulture);
47+
48+
Assert.AreEqual(expected.ToString(), doc);
49+
}
50+
2151
[Test]
2252
public void Can_serialize_a_list_which_is_the_content_of_root_element()
2353
{
@@ -289,7 +319,12 @@ public void Serializes_Properties_In_Specified_Order()
289319
Assert.AreEqual(expected.ToString(), doc);
290320
}
291321

292-
class Person
322+
interface INamed
323+
{
324+
string Name { get; set; }
325+
}
326+
327+
class Person : INamed
293328
{
294329
public string Name { get; set; }
295330

@@ -304,7 +339,7 @@ class Person
304339
public bool? IsCool { get; set; }
305340
}
306341

307-
class Item
342+
class Item : INamed
308343
{
309344
public string Name { get; set; }
310345

@@ -336,6 +371,12 @@ class WackyPerson
336371
public ContactData ContactData { get; set; }
337372
}
338373

374+
class NamedItems
375+
{
376+
[SerializeAs(Content = true)]
377+
public List<INamed> Items { get; set; }
378+
}
379+
339380
[SerializeAs(Name = "People")]
340381
class Contacts
341382
{
@@ -527,6 +568,32 @@ static XDocument GetSortedPropsXDoc()
527568
return doc;
528569
}
529570

571+
static XDocument GetNamedItemsXDoc(IFormatProvider culture)
572+
{
573+
var doc = new XDocument();
574+
var root = new XElement("NamedItems");
575+
var element = new XElement("Person");
576+
var items = new XElement("Items");
577+
578+
items.Add(new XElement("Item", new XElement("Name", "One"), new XElement("Value", 1)));
579+
580+
element.Add(
581+
new XElement("Name", "Foo"),
582+
new XElement("Age", 50),
583+
new XElement("Price", 19.95m.ToString(culture)),
584+
new XElement("StartDate", new DateTime(2009, 12, 18, 10, 2, 23).ToString(culture))
585+
);
586+
587+
element.Add(items);
588+
root.Add(element);
589+
root.Add(new XElement("Item", new XElement("Name", "Two"), new XElement("Value", 2)));
590+
root.Add(new XElement("Item", new XElement("Name", "Three"), new XElement("Value", 3)));
591+
592+
doc.Add(root);
593+
594+
return doc;
595+
}
596+
530597
static XDocument GetPeopleXDoc(IFormatProvider culture)
531598
{
532599
var doc = new XDocument();

0 commit comments

Comments
 (0)