11using System . Net . Http . Headers ;
22using System . Text ;
3+ using System . Text . Json ;
34using Communicator . Enums ;
45using Communicator . Helpers ;
56using Communicator . Models ;
89using Communicator . Models . Twilio ;
910using Communicator . Options ;
1011using Communicator . Services . Interfaces ;
11- using Newtonsoft . Json ;
12- using Newtonsoft . Json . Serialization ;
1312
1413namespace Communicator . Services . Implementations ;
1514
1615internal 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 }
0 commit comments