Remove the Newtonsoft.Json package and migrate to System.Text.Json#2125
Remove the Newtonsoft.Json package and migrate to System.Text.Json#2125EngRajabi wants to merge 28 commits intoThreeMammals:developfrom
Newtonsoft.Json package and migrate to System.Text.Json#2125Conversation
raman-m
left a comment
There was a problem hiding this comment.
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❕ |
raman-m
left a comment
There was a problem hiding this comment.
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.Jsonreference indefinitely for backward compatibility. - Implement the new
System.Text.Jsonfunctionality and set it as the default, as your PR suggests. - Create a new
Ocelot.Infrastructure.JsonUtilhelper to establish a concrete dependency on the consumed library (requires a new Core infrastructure interface). - Introduce a new global JSON setting in the
GlobalConfigurationofocelot.json, such asJsonOptionsand aTypeproperty, to choose between usingNewtonsoft.JsonorSystem.Text.Jsonlibraries. - 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.
| .AddControllersAsServices() | ||
| .AddAuthorization() | ||
| .AddNewtonsoftJson(); | ||
| .AddJsonOptions(op => |
There was a problem hiding this comment.
I'm hesitant to rewrite the documentation until all the code has been verified and approved.
There was a problem hiding this comment.
I do not believe we have the authority to change the default settings of the library. Providing recommendations in the documentation to the community should have reasonable goals!
I do not think all Ocelot solutions on the Internet should adhere to these JSON options.
There was a problem hiding this comment.
This change does not change the library's behavior, so changing this method does not cause any problems.
|
|
||
| .. _di-custom-builder: | ||
|
|
||
| Custom Builder |
There was a problem hiding this comment.
I understand that this sample might contain outdated code, yet it's essential to convert it into something usable. The sample illustrates how to override the default services in the DI feature. We can demonstrate how to revert to the old NewtonSoft services using new package versions. However, the rewriting should be deferred until all C# code is approved. Ultimately, updating the documentation should be the final step in the PR process.
| 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.
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
raman-m
left a comment
There was a problem hiding this comment.
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 |
fdca813 to
9ae0cc4
Compare
|
@EngRajabi @MohammadAminPourmoradian Sorry for merge conflicts! Please fix them by rebasing feature branch onto develop one! |
|
@EngRajabi @raman-m Who should resolve the merge conflicts? |
|
@ggnaegi Authors, indeed. However, it is well-known that most of our authors tend to be lazy with only a few exceptions. Second, if an author does not respond and develop their PR, then as team members, we can deprioritize the PR and put it into waiting status. Third, if the PR is accepted and included in a current release, then authors should be online. If they are offline, a team member takes responsibility to develop and deliver it, finally merging to the develop branch. Are these good instructions? Finally, the PR is not added to any milestones. I believe it should be developed further. |
908d84f to
0678e7a
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