Implement CamelCasePropertyNamesContractResolver into PluginNoStartup

This commit is contained in:
Loretta 2024-11-17 16:34:29 +01:00
parent 357858c28f
commit d51888b8a3
2 changed files with 9 additions and 2 deletions

View File

@ -77,8 +77,12 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
Message = viewModel.Body,
}
};
var jsonMessage = JsonConvert.SerializeObject(announcement, Formatting.Indented,
new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
var jsonMessage = JsonConvert.SerializeObject(announcement, Formatting.Indented, new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
});
await _logger.InformationAsync($"sending announcements");
await _announcementHubContext.Clients.All.SendAsync("send", jsonMessage);
//await _announcementHubContext.Clients.All.SendAsync("send", viewModel.Body.ToString());

View File

@ -8,6 +8,7 @@ using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Infrastructure;
@ -75,6 +76,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure
SerializeObjectExtensions.Options.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
SerializeObjectExtensions.Options.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
SerializeObjectExtensions.Options.NullValueHandling = NullValueHandling.Ignore;
SerializeObjectExtensions.Options.ContractResolver = new CamelCasePropertyNamesContractResolver();
application.UseEndpoints(endpoints =>
{
@ -84,5 +86,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure
options.AllowAnyMethod().AllowAnyHeader().AllowCredentials().SetIsOriginAllowed((hosts) => true);
});
}
}
}