Skip to content
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

DotNet Serialization Not Restoring Original Value, Unlike Newtonsoft #62

Open
CPMOliveira opened this issue Sep 9, 2024 · 2 comments
Open

Comments

@CPMOliveira
Copy link

Description: I encountered an issue when serializing and deserializing objects using the System.Text.Json. The value is not restored to its original state upon deserialization, unlike when using Newtonsoft.Json, which works as expected. This is critical when dealing with specific value types.

Example:

Length L = new(1d, LengthUnit.Meter);

// Using System.Text.Json
string L_Json_DotNet = System.Text.Json.JsonSerializer.Serialize(L);
Length L_Unit_DotNet = System.Text.Json.JsonSerializer.Deserialize<Length>(L_Json_DotNet)!;
Length.Equals(L, L_Unit_DotNet); // False

// Using Newtonsoft.Json
string L_Json_Newtonsoft = Newtonsoft.Json.JsonConvert.SerializeObject(L);
Length L_Unit_Newtonsoft = Newtonsoft.Json.JsonConvert.DeserializeObject<Length>(L_Json_Newtonsoft)!;
Length.Equals(L, L_Unit_Newtonsoft); // True

Expected Behavior: System.Text.Json serialization should restore the original object value, just like Newtonsoft.Json.

Environment:
EngineeringUnits Version: 2.2.98
.NET Version: 9.0 Preview 7

@MadsKirkFoged
Copy link
Owner

Hi CPMOliveira,
Thanks for reaching out!

You are right that we are yet to create support for System.Text.Json
Its on the backlog and now that we actually got a request for it, I will move it up the list.

If you got the skills and time you are also welcome to try if you can implement it yourself?

@MadsKirkFoged
Copy link
Owner

It is actually Fractions that does not have support for System.Text.Json which it a system we use for conversions between units.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants