-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove the Newtonsoft.Json
package and migrate to System.Text.Json
#2125
base: develop
Are you sure you want to change the base?
Conversation
build - Skipped |
Mohsen, if you don't mind, I will rebase the branch once again... I hope to fix the build. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the moment, I would appreciate it if you could eliminate all non-substantive changes such as:
- End of line characters
- Fixes to whitespace issues
- Formatting corrections
If this cannot be done, please inform me, and I will assist you. Let's concentrate on the actual changes.
Very well❕ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the excellent benchmark testing with the new JsonSerializerBenchmark
class!
I'm concerned that a direct upgrade to the Microsoft native library might work, but it could cause issues or even breaking changes for our development consumers. Therefore, we need to seek a more advanced and gentle solution through redesign.
My suggestions are:
- Maintain the old
Newtonsoft.Json
reference indefinitely for backward compatibility. - Implement the new
System.Text.Json
functionality and set it as the default, as your PR suggests. - Create a new
Ocelot.Infrastructure.JsonUtil
helper to establish a concrete dependency on the consumed library (requires a new Core infrastructure interface). - Introduce a new global JSON setting in the
GlobalConfiguration
ofocelot.json
, such asJsonOptions
and aType
property, to choose between usingNewtonsoft.Json
orSystem.Text.Json
libraries. - Instantiate and delegate serialization operations to the actual parser instance.
- Inject the new interface object into all consuming classes through the DI mechanism.
This method is more adaptable: we maintain backward compatibility while gradually transitioning to Microsoft's implementations to enhance performance.
@@ -53,14 +54,14 @@ public async Task<Response<FileConfiguration>> Get() | |||
|
|||
var bytes = queryResult.Response.Value; | |||
var json = Encoding.UTF8.GetString(bytes); | |||
var consulConfig = JsonConvert.DeserializeObject<FileConfiguration>(json); | |||
var consulConfig = JsonSerializer.Deserialize<FileConfiguration>(json, JsonSerializerOptionsExtensions.Web); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... The new JsonSerializer
is from the System.Text.Json
namespace.
But the package depends on Ocelot one and it consumes Ocelot interfaces.
Such hard changes constitute a major upgrade of the Ocelot Core and may introduce a breaking change, which will be detailed in the Release Notes.
I believe we need a more advanced solution.
Finally, the package should depend on Ocelot interfaces only!
@EngRajabi @MohammadAminPourmoradian Mohsen and Mohammad, congratulations! The PR has entered the official code review stage. The build is green and stable now. I've made some on-the-fly code review adjustments, including superficial changes. The pull request is now well-prepared for an easy review. @ggnaegi @RaynaldM Hello, I anticipate your thorough code review due to the significant and important upgrade in the Core involving the replacement of the JSON parsing library. I would value your consideration of my proposal to redesign the current draft solution, as I foresee potential issues. |
You gave a good suggestion, but is it really that much work? |
@raman-m let's check this... |
61baceb
to
93bea24
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JsonPath.Net
reference must be removed❗
By including this library reference, you are breaching our Development Process for the Ocelot core package! Refer to point 5:
The main Ocelot package must not have taken on any non MS dependencies.
The significant issue with this PR is the included reference. It is essential to eliminate this reference and begin utilizing the full capabilities of native Microsoft functionality: native .NET classes or native target lib.
@MohammadAminPourmoradian |
I replaced |
../test/Ocelot.UnitTests/Requester/MessageInvokerPoolTests.cs
../test/Ocelot.IntegrationTests/ocelot.json
../test/Ocelot.AcceptanceTests/Steps.cs
../test/Ocelot.AcceptanceTests/Steps.cs
../src/Ocelot/Requester/MessageInvokerPool.cs
Bump System.Text.Encodings.Web to 8.0.0
fdca813
to
9ae0cc4
Compare
In this request, we deleted the newtonsoft package and migrated to text json system.
The reason for the changes
The changes given include the removal of Newtonsoft. A benchmark has also been added for this
@MohammadAminPourmoradian helped me with this
BenchmarkDotNet v0.13.11, Windows 11 (10.0.22631.3880/23H2/2023Update/SunValley3)
Intel Core i7-10870H CPU 2.20GHz, 1 CPU, 16 logical and 8 physical cores
.NET SDK 8.0.303
[Host] : .NET 6.0.32 (6.0.3224.31407), X64 RyuJIT AVX2 [AttachedDebugger]
.NET 8.0 : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX2
Job=.NET 8.0 Runtime=.NET 8.0