Skip to content

Commit f4a9d0f

Browse files
authored
Merge pull request #1 from scottoffen/add-json-extensions
Improve JSON support
2 parents 30611c1 + 5ab407a commit f4a9d0f

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/FluentHttpClient/FluentHttpClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageTags>fluent httpclient rest http api web client</PackageTags>
1515
<AssemblyVersion>$(Version)</AssemblyVersion>
1616
<FileVersion>$(Version)</FileVersion>
17-
<Version>1.3.0</Version>
17+
<Version>1.4.0</Version>
1818
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1919
<PackageLicenseFile>LICENSE</PackageLicenseFile>
2020
<RepositoryUrl>https://github.com/scottoffen/fluenthttpclient</RepositoryUrl>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
4+
#if NET5_0_OR_GREATER
5+
using System.Net.Http.Json;
6+
#endif
7+
8+
namespace FluentHttpClient;
9+
10+
public static class RestRequestJsonExtensions
11+
{
12+
private static readonly JsonSerializerOptions _options = new JsonSerializerOptions
13+
{
14+
PropertyNameCaseInsensitive = true,
15+
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
16+
};
17+
18+
#if NET5_0_OR_GREATER
19+
public static RestRequestBuilder WithJsonContent(this RestRequestBuilder builder, object content)
20+
{
21+
return builder.WithJsonContent(content, _options);
22+
}
23+
24+
public static RestRequestBuilder WithJsonContent(this RestRequestBuilder builder, object content, JsonSerializerOptions options)
25+
{
26+
builder.Content = JsonContent.Create(content, options: options);
27+
return builder;
28+
}
29+
#endif
30+
}

0 commit comments

Comments
 (0)