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
Transitioning to System.Text.Json from Newtonsoft.Json #7021
Comments
volkanceylan
changed the title
Switching to System.Text.JSON from Newtonsoft.JSON
Transitioning to System.Text.Json from Newtonsoft.Json
Nov 18, 2023
Also note that System.Text.Json does not support field members, e.g. ones without get set. If you have any non property in your custom types convert them to properties. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Transitioning to System.Text.Json from Newtonsoft.Json in .NET
We are migrating to System.Text.Json from Newtonsoft.Json, as it is the recommended and more performant library in .NET.
Please note that the transition occured in 8.0.1 version.
Compatibility and Workarounds
There exist several compatibility issues between Newtonsoft and System.Text.Json. Check the following link for detailed insights: Migrate from Newtonsoft to System.Text.Json.
To ensure compatibility, we've implemented various workarounds such as using custom converters, specific serializer settings, etc. In versions before .NET 8, handling missing members by raising an exception was not feasible.
Update Requirements for Users
After the transition, users must add attributes specific to System.Text.Json to properties and classes that previously had Newtonsoft-specific attributes. For instance:
Newtonsoft.Json.JsonProperty
withSystem.Text.Json.Serialization.JsonPropertyName
.JsonIgnore
, among others.An example includes the
UserListRequest DataProtector
property, which previously had aJsonIgnore
attribute specific to Newtonsoft.Transition Guidelines
The converter classes unique to System.Text.Json reside in the
Serenity.JsonConverters
namespace and end withJsonConverter
. For example:JsonRowConverter
.Serenity.JsonConverters.RowJsonConverter
.When using
[JsonConverter(typeof(...))]
attribute, users should exercise caution to specify the correct type, as the attribute name remains the same for both libraries.To transition, users need to:
.AddNewtonsoftJson
block inStartup.cs
.Behavior Changes
Unlike Newtonsoft.Json,
IncludeNulls
is replaced withWriteNulls
as we will only ignore nulls during serialization. The parameter names are also changed towriteNulls
to align with this behavior.System.Text.Json will be used for
JSON.Stringify
methods, and there won't be any means to use Newtonsoft other than manually callingNewtonsoft.Json.JsonConvert
, etc.Retaining Newtonsoft.Json Reference
We have not yet removed the Newtonsoft.Json reference as it is necessary for referencing serialization attributes, ensuring compatibility. While we may consider its removal in the future, it won't happen immediately.
The text was updated successfully, but these errors were encountered: