Skip to content

Commit 2f77cac

Browse files
committed
feat: added support of xml deserialization
1 parent 776c0a6 commit 2f77cac

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This repos contains tool classes in C# for multiple types of usage.
1313
* WakeOnLan: Power on a device with it mac address.
1414

1515
* `FrApp42.Web` - [Link](https://www.nuget.org/packages/FrApp42.Web)
16-
* Request: Make API request for any of your C# projects. ⚠️ *SOAP requests are not supported.* ⚠️
16+
* Request: Make API request for any of your C# projects.
1717

1818
## Authors
1919
* [AnthoDingo](https://github.com)

Web/API/Request.cs

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Newtonsoft.Json;
33
using System.Net.Http.Headers;
44
using System.Text;
5+
using System.Xml.Serialization;
56

67
namespace FrApp42.Web.API
78
{
@@ -392,8 +393,24 @@ private async Task<Result<T>> Process<T>(HttpRequestMessage request)
392393

393394
if (response.IsSuccessStatusCode)
394395
{
395-
Stream ContentResponse = await response.Content?.ReadAsStreamAsync();
396-
result.Value = await System.Text.Json.JsonSerializer.DeserializeAsync<T>(ContentResponse);
396+
string MediaType = response.Content?.Headers?.ContentType?.MediaType.ToLower();
397+
string ContentResponse = await response.Content?.ReadAsStringAsync();
398+
399+
switch (true)
400+
{
401+
case bool b when (MediaType.Contains("application/xml")):
402+
XmlSerializer xmlSerializer = new(typeof(T));
403+
StringReader reader = new(ContentResponse);
404+
405+
result.Value = (T)xmlSerializer.Deserialize(reader);
406+
break;
407+
case bool b when (MediaType.Contains("application/json")):
408+
result.Value = JsonConvert.DeserializeObject<T>(ContentResponse);
409+
break;
410+
default:
411+
result.Value = default;
412+
break;
413+
}
397414
}
398415
else
399416
{

Web/Web.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<PackageReadmeFile>README.md</PackageReadmeFile>
2121
<Company>FrenchyApps42</Company>
2222
<PackageIcon>logo.png</PackageIcon>
23-
<Version>1.1.0</Version>
23+
<Version>1.2.0</Version>
2424
</PropertyGroup>
2525

2626
<ItemGroup>

0 commit comments

Comments
 (0)