-
Notifications
You must be signed in to change notification settings - Fork 43
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
feat: Replace Newtonsoft.Json with System.Text.Json #109
feat: Replace Newtonsoft.Json with System.Text.Json #109
Conversation
- IgnoreNullValues is obsolete, i kept is because it IgnoreCondition is >net7 - Removed package from core, and readded package in MongoDbProvider, only used there. Test project(s) still use newtonsoft.json, but we can evaluate this later.
@followynne @mo-esmp review request 🚀 (i thought github had a 'request review' button? well could not find it...) |
Hey @sommmen ,you can add reviewers in the top right corner, I just did it for you - will review as soon as I have sime time 😉 |
Hey @sommmen, checked your PRs, thanks a lot for the work - I really appreciate the goal of replacing Newtonsoft! 💯 From what I saw, we shouldn't expect any hard/strange serialization in the library thus we should be safe to do this first replacement (usually the issue with STJ is that it's strict and less "gentle" on dirty data, while Newtonsoft accepts anything you throw at it :D) In a second moment, we can work on replacing it in Elastic and Mongo libs. The only request I have before closing the PR, if you have the time to do it, is to replace NJ in the tests projects, on files tests/Serilog.Ui.Common.Tests/DataSamples/PropertiesFaker.cs We won't touch it in Mongo test setup but I think it should be done on all the other parts 😄 |
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.
As said in the main comment, I'd prefer to remove all the unnecessary Netwonsoft references in the test projects.
Yeah I'll check it probs tomorrow and if I don't have the time Friday I usually have a spare hour or two. 👍 |
Updated the PR. Merged upstream. LogModelFaker.cs The exception is now just stringified because STJ does not serialize an exception without a custom converter. This could be added or picked up from somewhere, but in theory no assumption should be made about the log model's exception field having a piece of json inside - so i decided the tests should also reflect this, and just using LogModelPropsCollector.cs has some calls to MongoDbLogModelFaker.cs Since the Exception property is no longer some json, i simply generate a new fake exception for the Properties.cs Changed the |
looks good to me, I'm not 100% sure about the assumption that the Exception property could not contain JSON, since the user should be making the choice between JSON or XML (if I remember right), but from another point of view you're right in making them more generic for all possible entries. Approved, I'll leave to @mo-esmp the last review :) |
I think you're confused with the Like here's a sample from my production database. The Exception column is simply @mo-esmp when you decide to merge this in, please also push a release since that would contain the fix to #108 which is not on nuget yet and i'd like that fix :).
|
@@ -21,7 +20,7 @@ private static Faker<LogModel> LogsRules() | |||
.RuleFor(p => p.RowNo, f => f.Database.Random.Int()) | |||
.RuleFor(p => p.Level, f => f.PickRandom(LogLevels)) | |||
.RuleFor(p => p.Properties, PropertiesFaker.SerializedProperties) | |||
.RuleFor(p => p.Exception, (f) => JsonConvert.SerializeObject(f.System.Exception())) | |||
.RuleFor(p => p.Exception, (f) => f.System.Exception().ToString()) |
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.
@followynne A serialized exception is not needed here? because the output of .ToString()
is different with a serialized exception.
@sommmen Thanks for the PR. |
Yep,I'll try to do it this weekend together with mssql 2.2.3, as soon as I can 👍 |
Closes #61.
This PR aims to remove jsonnet and replace it with STJ.
JsonNet was removed from Core and Web projects, including .nuspec of the web project.
Only 2 providers now use JsonNet, Elasticsearch (via Nest.JsonNetSerializer) and MongoDb.
MongoDb's ref to JsonNet could also be removed, but it serializes
[BsonElement("Properties")]
so it looked to risky. Perhaps in the future we can reevaluate this.One test failed;
It_serializes_an_error_on_exception
which is because there was a double serialization for the error value.I tried to fix the code so the test would remain intact, but that was hard to do.
Then when i decided i had to change the code anyways, and found no text references to 'errorMessage' anywhere else, i decided to upgrade the error feature to use the RFC 7807 - Problem Details for HTTP APIs. this is an industry standard also used by net core. Easily implemented with help from the renowned Andrew Lock.
The test projects may still use JsonNet - i deemed that okay since its not a dependency shipped to the library consumer.
Tested with the sample app - it looks good to me. Feel free to edit or remove this PR, let me know what you think.