-
Notifications
You must be signed in to change notification settings - Fork 384
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
Add serialization support for System.Text.Json (Attempt #2) #966
Conversation
…lso be used with System.Text.Json WIP
(Haven't tried this yet, but thanks for giving it a shot!) |
FYI, #972 was merged. Also, there was some discussion that reveals our current JSON schema is maybe not optimal. |
@angularsen Is there any ETA on this? Maybe some help is required? We miss this feature a lot, it's the only thing that holds us back from migrating a big project to System.Text.Json :) |
@dmytro-gokun If you want to help out, then great! I am not actively working on it myself, but @lipchev has done quite a bit of work on json lately. Some relevant background: In particular, we see that maybe the current JSON schema can be simplified a bit, removing fields @lipchev Do you plan to attack system.text.json anytime soon? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I can see that its quite hard to find a efficient way to make Units.NET work with STJ, but wouldn't it for now be an option to just use the
and then above every
As is said, I get it that the Parse method is not that efficient and on the long run we may should find another way, but this will at least make Units.NET work with STJ. I would implement this, if you agree. |
Okay I found another solution how this will work with STJ. Install NuGet package ZCS.DataContractResolver and then replace the default
|
Thanks for sharing @maxreb . Yes, DataContract should be one way to achieve this. Another option is to implement custom converters, as this PR originally tried to. I believe that gives more control on the serialized format, but maybe data contract approach works well enough already. |
Second attempt for System.Text.Json support.
Should close #901.
Tried to adress issues mentioned by @chucker in #905 (thanks!).
The problem lies in non-polymorphic deserialization IMO. The original deserialization failed when the constructor had an IQuantity subtype as argument (e.g. Information) but the converter converted to IQuantity. I addressed that by returning specific converters in the factory as described in https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-converters-how-to?pivots=dotnet-5-0#support-round-trip-for-stackt.
Further notes:
Hope it works and helps :-)