-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
[BUG] Json serialization behavior is not the same on framework as it is on core/5+ #71
Comments
Let me comment on your initial statement a little. You wrote:
There is no "correct" serialization for this type (and for the And BCL versions of I don't particularly appreciate adding dependencies like
And of course, you can create this new NuGet package with converters and I'll just add a link to it into README. |
@all-contributors please add @KieranDevvs for ideas |
I've put up a pull request to add @KieranDevvs! 🎉 |
@OlegRa Thanks for the feedback. I appreciate not wanting to add a serialization library dependency, and I think having a separate NuGet package for the converters would be great. I don't think this should be left to the user to implement as I see much more benefit and ease of use from standardising the converters to match the .NET core/5+ behaviour. This would mean users would have to decorate their properties / fields with |
…t.Json` serialization/deserialization support.
@OlegRa Oh I didn't expect you to create the project AND do the implementation, I was going to contribute but I wont argue about not having to do the work 🥳. Do you have an ETA on the NuGet package release? I can start swapping out my existing converters in place of yours 🙂. |
If you have an alternative implementation, you can create your own NuGet package. It's always better to have two OSS alternatives than one 🥇 My implementation is based on the I will publish this NuGet package later this evening (European time) after completing GitHub action for it. |
@KieranDevvs Finally it's published. Please, test and provide your feedback here or in a separate issue(s). |
I wonder...does it not suffice to use a type converter to\from string? I think both json.net and STJ would then just work without any extra work and no need for separate package? |
I don't understand your question. {
"year": 2001,
"month": 2,
"day": 19,
"hour": 17,
....
} And now if these two applications want to interface each other, they need to: A) Share converter types or B) Standardize their converters. TLDR; I think its better to offer a standard approach out of the box and if you decide to do your own thing, then fine, but you're to blame if it doesn't go well. |
I mean, could it suffice to use a json independent type converter like this that could live in the main package (meaning, in the System.DateTimeOnly package itself):
"As mentioned in this issue, its not favorable to let the consumers each individually build their own" "TLDR; I think its better to offer a standard approach out of the box and if you decide to do your own thing, then fine, but you're to blame if it doesn't go well." |
@osexpert There are two problems with the
The current approach is not ideal but it's better than nothing. Right now it has only one limitation - the source generator goes crazy and tries to use built-in converters for backported types even on unsupported platforms. For this scenario, we'll need a more complex workaround. |
That is a problem for sure:-) I incorrectly remembered it did. Thanks. |
@KieranDevvs, I closed it as completed after this helper NuGet package's "official" release. If you have any issues/bugs or some ideas for better documentation, please open another issue(s). |
Describe the bug
Deserializing the structs on Framework from valid JSON results in a zero value.
Deserializing the structs on Core/NET 5+ results in the correct representation.
The JSON is serialized correctly but it would appear the fields aren't populated correctly when deserializing due to the fact that the properties have private setters.
System.Text.Json
gained the ability to deserialise properties with private setters in .NET 5.Potential solutions:
[JsonConstructor]
to the structs.DateOnly
andTimeOnly
).To Reproduce
.NET 8
.NET Framework 4.8
The text was updated successfully, but these errors were encountered: