Skip to content

Commit

Permalink
Remove Newtonsoft (#14572)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Alhayek <[email protected]>
Co-authored-by: Sebastien Ros <[email protected]>
  • Loading branch information
3 people committed Feb 2, 2024
1 parent a738738 commit 71fde7c
Show file tree
Hide file tree
Showing 471 changed files with 4,339 additions and 2,542 deletions.
1 change: 0 additions & 1 deletion src/OrchardCore.Build/Dependencies.AspNetCore.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<PackageManagement Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="$(AspNetCorePackagesVersion)" />
<PackageManagement Include="Microsoft.AspNetCore.Authentication.Twitter" Version="$(AspNetCorePackagesVersion)" />
<PackageManagement Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="$(AspNetCorePackagesVersion)" />
<PackageManagement Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="$(AspNetCorePackagesVersion)" />
<PackageManagement Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="$(AspNetCorePackagesVersion)" />
<PackageManagement Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(AspNetCorePackagesVersion)" />
<PackageManagement Include="Microsoft.AspNetCore.Owin" Version="$(AspNetCorePackagesVersion)" />
Expand Down
11 changes: 5 additions & 6 deletions src/OrchardCore.Build/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<PackageManagement Include="Moq" Version="4.20.70" />
<PackageManagement Include="ncrontab" Version="3.3.3" />
<PackageManagement Include="NEST" Version="7.17.5" />
<PackageManagement Include="Newtonsoft.Json" Version="13.0.3" />
<PackageManagement Include="NJsonSchema" Version="11.0.0" />
<PackageManagement Include="NLog.Web.AspNetCore" Version="5.3.8" />
<PackageManagement Include="NodaTime" Version="3.1.10" />
Expand All @@ -64,11 +63,11 @@
<PackageManagement Include="xunit" Version="2.6.6" />
<PackageManagement Include="xunit.analyzers" Version="1.10.0" />
<PackageManagement Include="xunit.runner.visualstudio" Version="2.5.6" />
<PackageManagement Include="YesSql" Version="4.1.0" />
<PackageManagement Include="YesSql.Abstractions" Version="4.1.0" />
<PackageManagement Include="YesSql.Core" Version="4.1.0" />
<PackageManagement Include="YesSql.Filters.Abstractions" Version="4.1.0" />
<PackageManagement Include="YesSql.Filters.Query" Version="4.1.0" />
<PackageManagement Include="YesSql" Version="5.0.0-beta-0002" />
<PackageManagement Include="YesSql.Abstractions" Version="5.0.0-beta-0002" />
<PackageManagement Include="YesSql.Core" Version="5.0.0-beta-0002" />
<PackageManagement Include="YesSql.Filters.Abstractions" Version="5.0.0-beta-0002" />
<PackageManagement Include="YesSql.Filters.Query" Version="5.0.0-beta-0002" />
<PackageManagement Include="ZString" Version="2.5.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OrchardCore.AdminMenu.Services;
using OrchardCore.Deployment;

Expand All @@ -24,18 +23,16 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan
return;
}

var data = new JArray();
result.Steps.Add(new JObject(
new JProperty("name", "AdminMenu"),
new JProperty("data", data)
));

// For each AdminNode, store info about its concrete type: linkAdminNode, contentTypesAdminNode etc...
var serializer = new JsonSerializer() { TypeNameHandling = TypeNameHandling.Auto };
var data = new JsonArray();
result.Steps.Add(new JsonObject
{
["name"] = "AdminMenu",
["data"] = data,
});

foreach (var adminMenu in (await _adminMenuService.GetAdminMenuListAsync()).AdminMenu)
{
var objectData = JObject.FromObject(adminMenu, serializer);
var objectData = JObject.FromObject(adminMenu);
data.Add(objectData);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Linq;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OrchardCore.AdminMenu.Services;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;
Expand Down Expand Up @@ -30,11 +29,11 @@ public async Task ExecuteAsync(RecipeExecutionContext context)

var model = context.Step.ToObject<AdminMenuStepModel>();

var serializer = new JsonSerializer() { TypeNameHandling = TypeNameHandling.Auto };
// var serializer = new JsonSerializer() { TypeNameHandling = TypeNameHandling.Auto };

foreach (var token in model.Data.Cast<JObject>())
foreach (var token in model.Data.Cast<JsonObject>())
{
var adminMenu = token.ToObject<Models.AdminMenu>(serializer);
var adminMenu = token.ToObject<Models.AdminMenu>(/*serializer*/);

// When the id is not supplied generate an id, otherwise replace the menu if it exists, or create a new menu.
if (string.IsNullOrEmpty(adminMenu.Id))
Expand All @@ -51,6 +50,6 @@ public async Task ExecuteAsync(RecipeExecutionContext context)

public class AdminMenuStepModel
{
public JArray Data { get; set; }
public JsonArray Data { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.AdminMenu/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public override void ConfigureServices(IServiceCollection services)
services.AddSingleton<IAdminNodeProviderFactory>(new AdminNodeProviderFactory<LinkAdminNode>());
services.AddScoped<IAdminNodeNavigationBuilder, LinkAdminNodeNavigationBuilder>();
services.AddScoped<IDisplayDriver<MenuItem>, LinkAdminNodeDriver>();

services.AddAdminNode<LinkAdminNode>();
services.AddAdminNode<PlaceholderAdminNode>();
}

public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@model LinkAdminNodeViewModel
@using Newtonsoft.Json
@using Newtonsoft.Json.Serialization
@using System.Text.Json
@using System.Text.Json.Nodes

<style asp-src="~/OrchardCore.AdminMenu/Styles/admin-menu.min.css" debug-src="~/OrchardCore.AdminMenu/Styles/admin-menu.css" at="Head" depends-on="admin"></style>
<style asp-src="~/OrchardCore.AdminMenu/Styles/admin-menu-icon-picker.min.css" debug-src="~/OrchardCore.AdminMenu/Styles/admin-menu-icon-picker.css" at="Head" depends-on="admin"></style>
Expand Down Expand Up @@ -73,8 +73,8 @@

<div class="mb-3">
@{
var selectedItems = JsonConvert.SerializeObject(Model.SelectedItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
var allItems = JsonConvert.SerializeObject(Model.AllItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
var selectedItems = JConvert.SerializeObject(Model.SelectedItems, JOptions.CamelCase);
var allItems = JConvert.SerializeObject(Model.AllItems, JOptions.CamelCase);
}

<script asp-name="admin-menu-permission-picker" asp-src="~/OrchardCore.AdminMenu/Scripts/admin-menu-permission-picker.min.js" debug-src="~/OrchardCore.AdminMenu/Scripts/admin-menu-permission-picker.js" at="Foot" depends-on="vuejs, vue-multiselect"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@model PlaceholderAdminNodeViewModel
@using Newtonsoft.Json
@using Newtonsoft.Json.Serialization
@using System.Text.Json
@using System.Text.Json.Nodes

<style asp-src="~/OrchardCore.AdminMenu/Styles/admin-menu.min.css" debug-src="~/OrchardCore.AdminMenu/Styles/admin-menu.css" at="Head" depends-on="admin"></style>
<style asp-src="~/OrchardCore.AdminMenu/Styles/admin-menu-icon-picker.min.css" debug-src="~/OrchardCore.AdminMenu/Styles/admin-menu-icon-picker.css" at="Head" depends-on="admin"></style>
Expand Down Expand Up @@ -63,8 +63,8 @@

<div class="mb-3">
@{
var selectedItems = JsonConvert.SerializeObject(Model.SelectedItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
var allItems = JsonConvert.SerializeObject(Model.AllItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
var selectedItems = JConvert.SerializeObject(Model.SelectedItems, JOptions.CamelCase);
var allItems = JConvert.SerializeObject(Model.AllItems, JOptions.CamelCase);
}

<script asp-name="admin-menu-permission-picker" asp-src="~/OrchardCore.AdminMenu/Scripts/admin-menu-permission-picker.min.js" debug-src="~/OrchardCore.AdminMenu/Scripts/admin-menu-permission-picker.js" at="Foot" depends-on="vuejs, vue-multiselect"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ public class GraphQLMiddleware
private readonly GraphQLSettings _settings;
private readonly IDocumentExecuter _executer;
internal static readonly Encoding _utf8Encoding = new UTF8Encoding(false);
private readonly static MediaType _jsonMediaType = new("application/json");
private readonly static MediaType _graphQlMediaType = new("application/graphql");
private readonly static JsonSerializerOptions _jsonSerializerOptions = new() { WriteIndented = false, PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
private static readonly MediaType _jsonMediaType = new("application/json");
private static readonly MediaType _graphQlMediaType = new("application/graphql");

public GraphQLMiddleware(
RequestDelegate next,
Expand Down Expand Up @@ -101,7 +100,7 @@ private async Task ExecuteAsync(HttpContext context, ISchemaFactory schemaServic
}
else
{
request = await JsonSerializer.DeserializeAsync<GraphQLRequest>(context.Request.Body, _jsonSerializerOptions);
request = await JsonSerializer.DeserializeAsync<GraphQLRequest>(context.Request.Body, JOptions.CamelCase);
}
}
else
Expand Down Expand Up @@ -189,7 +188,7 @@ private static GraphQLRequest CreateRequestFromQueryString(HttpContext context,

if (context.Request.Query.ContainsKey("variables"))
{
request.Variables = JsonSerializer.Deserialize<JsonElement>(context.Request.Query["variables"], _jsonSerializerOptions);
request.Variables = JConvert.DeserializeObject<JsonElement>(context.Request.Query["variables"], JOptions.CamelCase);
}

if (context.Request.Query.ContainsKey("operationName"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Nodes;
using System.Text.Json.Settings;
using System.Threading.Tasks;
using Fluid;
using Fluid.Values;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
using OrchardCore.Autoroute.Core.Indexes;
using OrchardCore.Autoroute.Models;
using OrchardCore.Autoroute.ViewModels;
Expand Down Expand Up @@ -70,7 +71,7 @@ public override async Task PublishedAsync(PublishContentContext context, Autorou
{
_contentManager ??= _serviceProvider.GetRequiredService<IContentManager>();
var containedAspect = await _contentManager.PopulateAspectAsync<ContainedContentItemsAspect>(context.PublishingItem);
await CheckContainedHomeRouteAsync(part.ContentItem.ContentItemId, containedAspect, context.PublishingItem.Content);
await CheckContainedHomeRouteAsync(part.ContentItem.ContentItemId, containedAspect, (JsonObject)context.PublishingItem.Content);
}

// Update entries from the index table after the session is committed.
Expand Down Expand Up @@ -193,13 +194,13 @@ private Task RemoveTagAsync(AutoroutePart part)
return _tagCache.RemoveTagAsync($"slug:{part.Path}");
}

private async Task CheckContainedHomeRouteAsync(string containerContentItemId, ContainedContentItemsAspect containedAspect, JObject content)
private async Task CheckContainedHomeRouteAsync(string containerContentItemId, ContainedContentItemsAspect containedAspect, JsonObject content)
{
foreach (var accessor in containedAspect.Accessors)
{
var jItems = accessor.Invoke(content);

foreach (var jItem in jItems.Cast<JObject>())
foreach (var jItem in jItems.Cast<JsonObject>())
{
var contentItem = jItem.ToObject<ContentItem>();
var handlerAspect = await _contentManager.PopulateAspectAsync<RouteHandlerAspect>(contentItem);
Expand All @@ -213,7 +214,7 @@ private async Task CheckContainedHomeRouteAsync(string containerContentItemId, C
await SetHomeRouteAsync(autoroutePart, homeRoute =>
{
homeRoute[_options.ContentItemIdKey] = containerContentItemId;
homeRoute[_options.JsonPathKey] = jItem.Path;
homeRoute[_options.JsonPathKey] = jItem.GetNormalizedPath();
});

break;
Expand All @@ -236,18 +237,18 @@ private async Task GenerateContainedPathsFromPatternAsync(ContentItem contentIte

// Build the entries for this content item to evaluate for duplicates.
var entries = new List<AutorouteEntry>();
await PopulateContainedContentItemRoutesAsync(entries, part.ContentItem.ContentItemId, containedAspect, contentItem.Content, part.Path);
await PopulateContainedContentItemRoutesAsync(entries, part.ContentItem.ContentItemId, containedAspect, (JsonObject)contentItem.Content, part.Path);

await ValidateContainedContentItemRoutesAsync(entries, part.ContentItem.ContentItemId, containedAspect, contentItem.Content, part.Path);
await ValidateContainedContentItemRoutesAsync(entries, part.ContentItem.ContentItemId, containedAspect, (JsonObject)contentItem.Content, part.Path);
}

private async Task PopulateContainedContentItemRoutesAsync(List<AutorouteEntry> entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JObject content, string basePath)
private async Task PopulateContainedContentItemRoutesAsync(List<AutorouteEntry> entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JsonObject content, string basePath)
{
foreach (var accessor in containedContentItemsAspect.Accessors)
{
var jItems = accessor.Invoke(content);

foreach (var jItem in jItems.Cast<JObject>())
foreach (var jItem in jItems.Cast<JsonObject>())
{
var contentItem = jItem.ToObject<ContentItem>();
var handlerAspect = await _contentManager.PopulateAspectAsync<RouteHandlerAspect>(contentItem);
Expand All @@ -260,7 +261,7 @@ private async Task PopulateContainedContentItemRoutesAsync(List<AutorouteEntry>
path = (basePath.EndsWith('/') ? basePath : basePath + '/') + handlerAspect.Path.TrimStart('/');
}

entries.Add(new AutorouteEntry(containerContentItemId, path, contentItem.ContentItemId, jItem.Path)
entries.Add(new AutorouteEntry(containerContentItemId, path, contentItem.ContentItemId, jItem.GetNormalizedPath())
{
DocumentId = contentItem.Id
});
Expand All @@ -273,13 +274,13 @@ private async Task PopulateContainedContentItemRoutesAsync(List<AutorouteEntry>
}
}

private async Task ValidateContainedContentItemRoutesAsync(List<AutorouteEntry> entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JObject content, string basePath)
private async Task ValidateContainedContentItemRoutesAsync(List<AutorouteEntry> entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JsonObject content, string basePath)
{
foreach (var accessor in containedContentItemsAspect.Accessors)
{
var jItems = accessor.Invoke(content);

foreach (var jItem in jItems.Cast<JObject>())
foreach (var jItem in jItems.Cast<JsonObject>())
{
var contentItem = jItem.ToObject<ContentItem>();
var containedAutoroutePart = contentItem.As<AutoroutePart>();
Expand All @@ -297,7 +298,7 @@ private async Task ValidateContainedContentItemRoutesAsync(List<AutorouteEntry>
containedAutoroutePart.Apply();

// Merge because we have disconnected the content item from it's json owner.
jItem.Merge(contentItem.Content, new JsonMergeSettings
jItem.Merge((JsonObject)contentItem.Content, new JsonMergeSettings
{
MergeArrayHandling = MergeArrayHandling.Replace,
MergeNullValueHandling = MergeNullValueHandling.Merge
Expand All @@ -315,7 +316,7 @@ private async Task ValidateContainedContentItemRoutesAsync(List<AutorouteEntry>
containedAutoroutePart.Apply();

// Merge because we have disconnected the content item from it's json owner.
jItem.Merge(contentItem.Content, new JsonMergeSettings
jItem.Merge((JsonObject)contentItem.Content, new JsonMergeSettings
{
MergeArrayHandling = MergeArrayHandling.Replace,
MergeNullValueHandling = MergeNullValueHandling.Merge
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using System.Text.Json.Nodes;

namespace OrchardCore.ContentManagement.Metadata.Models;

Expand All @@ -13,8 +13,8 @@ public static TField GetContentField<TField>(
ContentItem contentItem)
where TField : ContentField
{
if (((JObject)contentItem.Content)[fieldDefinition.PartDefinition.Name] is not JObject jPart ||
jPart[fieldDefinition.Name] is not JObject jField)
if (((JsonObject)contentItem.Content)[fieldDefinition.PartDefinition.Name] is not JsonObject jPart ||
jPart[fieldDefinition.Name] is not JsonObject jField)
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Newtonsoft.Json.Linq;
using System.Text.Json.Nodes;

namespace OrchardCore.ContentFields.Fields
{
Expand All @@ -13,9 +13,9 @@ public static class UserNamesExtensions
/// </remarks>
public static string[] GetUserNames(this UserPickerField userPickerField)
{
var userNames = userPickerField.Content["UserNames"] as JArray;
var userNames = (JsonArray)userPickerField.Content["UserNames"];

return userNames != null ? userNames.ToObject<string[]>() : [];
return userNames is not null ? userNames.ToObject<string[]>() : [];
}

/// <summary>
Expand Down
Loading

0 comments on commit 71fde7c

Please sign in to comment.