Skip to content

Commit b06868c

Browse files
authored
Merge pull request #11 from PandaTechAM/development
newtonsoft removal
2 parents 4872bc3 + fbaa86d commit b06868c

File tree

3 files changed

+15
-30
lines changed

3 files changed

+15
-30
lines changed

src/Communicator/Communicator.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
<PackageReadmeFile>Readme.md</PackageReadmeFile>
99
<Authors>Pandatech</Authors>
1010
<Copyright>MIT</Copyright>
11-
<Version>2.0.0</Version>
11+
<Version>2.1.0</Version>
1212
<PackageId>Pandatech.Communicator</PackageId>
1313
<Title>SMS and Email Communication helper</Title>
1414
<PackageTags>Pandatech, library, Sms, Email, Messages</PackageTags>
1515
<Description>A versatile .NET library for integrating SMS and email functionalities. Supports multiple SMS providers and easy configuration through appsettings.json or web builders, ideal for efficient and reliable messaging in any application..</Description>
1616
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-communicator</RepositoryUrl>
17-
<PackageReleaseNotes>.Net 9 Upgrade</PackageReleaseNotes>
17+
<PackageReleaseNotes>Newton soft removal</PackageReleaseNotes>
1818
</PropertyGroup>
1919

2020
<ItemGroup>
@@ -26,7 +26,6 @@
2626
<PackageReference Include="MailKit" Version="4.8.0" />
2727
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
2828
<PackageReference Include="MimeKit" Version="4.8.0" />
29-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
3029
<PackageReference Include="Pandatech.RegexBox" Version="3.0.0" />
3130
</ItemGroup>
3231

src/Communicator/Services/Implementations/SmsService.cs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Net.Http.Headers;
22
using System.Text;
3+
using System.Text.Json;
34
using Communicator.Enums;
45
using Communicator.Helpers;
56
using Communicator.Models;
@@ -8,13 +9,17 @@
89
using Communicator.Models.Twilio;
910
using Communicator.Options;
1011
using Communicator.Services.Interfaces;
11-
using Newtonsoft.Json;
12-
using Newtonsoft.Json.Serialization;
1312

1413
namespace Communicator.Services.Implementations;
1514

1615
internal class SmsService(CommunicatorOptions options, IHttpClientFactory httpClientFactory) : ISmsService
1716
{
17+
private static JsonSerializerOptions SnakeCaseJsonSerializerOption =>
18+
new()
19+
{
20+
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
21+
};
22+
1823
private string _channel = null!;
1924
private HttpClient _httpClient = null!;
2025
private SmsConfiguration _smsConfiguration = null!;
@@ -141,14 +146,8 @@ private async Task<List<GeneralSmsResponse>> SendSmsViaDexatelAsync(SmsMessage s
141146

142147
var responseContent = await response.Content.ReadAsStringAsync(cancellationToken);
143148

144-
var responseObject = JsonConvert.DeserializeObject<DexatelSmsSendResponse>(responseContent,
145-
new JsonSerializerSettings
146-
{
147-
ContractResolver = new DefaultContractResolver
148-
{
149-
NamingStrategy = new SnakeCaseNamingStrategy()
150-
}
151-
});
149+
var responseObject =
150+
JsonSerializer.Deserialize<DexatelSmsSendResponse>(responseContent, SnakeCaseJsonSerializerOption);
152151

153152
return responseObject?.Data
154153
.Select(x =>
@@ -171,14 +170,7 @@ private async Task<HttpResponseMessage> PostAsyncViaDexatelHttpClient(DexatelSms
171170
return await _httpClient.PostAsync(
172171
$"{SmsProviderIntegrations.BaseUrls[_smsConfiguration.Provider]}/v1/messages",
173172
new StringContent(
174-
JsonConvert.SerializeObject(request,
175-
new JsonSerializerSettings
176-
{
177-
ContractResolver = new DefaultContractResolver
178-
{
179-
NamingStrategy = new SnakeCaseNamingStrategy()
180-
}
181-
}),
173+
JsonSerializer.Serialize(request, SnakeCaseJsonSerializerOption),
182174
Encoding.UTF8,
183175
"application/json"),
184176
cancellationToken);
@@ -195,14 +187,8 @@ private async Task<List<GeneralSmsResponse>> SendSmsViaTwilioAsync(SmsMessage sm
195187

196188
var responseContent = await response.Content.ReadAsStringAsync(cancellationToken);
197189

198-
var responseObject = JsonConvert.DeserializeObject<TwilioSmsSendResponse>(responseContent,
199-
new JsonSerializerSettings
200-
{
201-
ContractResolver = new DefaultContractResolver
202-
{
203-
NamingStrategy = new SnakeCaseNamingStrategy()
204-
}
205-
});
190+
var responseObject =
191+
JsonSerializer.Deserialize<TwilioSmsSendResponse>(responseContent, SnakeCaseJsonSerializerOption);
206192

207193
result.Add(responseObject ?? new TwilioSmsSendResponse());
208194
}

test/Communicator.Demo/Communicator.Demo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
12-
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.0.0" />
12+
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.1.0" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

0 commit comments

Comments
 (0)