-
Notifications
You must be signed in to change notification settings - Fork 47
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
Nullable readonly structs are not deserialized with the corresponding constructor call #477
Comments
Issue-Label Bot is automatically applying the label Links: app homepage, dashboard and code for this bot. |
Branch issues/fix/i477 created! |
WOW @feO2x I am astounded that this doesn't work as expected! Actually I am not sure what is more astounding, the fact that this doesn't work, or that it's taken someone this long to point it out. 😅 I will look into this now and see if I can track down what is going on. Thank you for reporting it. 👍 |
Gosh, I have been spending more time trying to figure out how we could have missed this issue up until this point than actually seeing what's wrong. It looks like we cover:
But we do not cover:
To further summarize, this is what we have tests against:
But we do not have something like this:
Or basically what was submitted here in the original issue. This somewhat solves my confusion/astonishment over how this hasn't been tracked yet. Now onto seeing if we can actually fix this. Here goes nothing. :P |
I should also add that the above is based on the default serializer, without any extensions applied to it. The reason why this class works in the provided issue:
Is that the Sorry, it's seriously tripping me out that this isn't covered. 😅 I guess part of my surprise is that I use a lot of |
No worries! I'm very happy that ExtendedXmlSerializer actually supports these scenarios that we have. Most other serializers don't, and that's why there is a lot of programming against dumb DTOs. |
Alrighty @feO2x check out this build: If it works for you we'll get this deployed to NuGet on Tuesday. Otherwise please let me know of any issues you find and I will look into them for you. 👍 |
Doh @feO2x looks like you are running into a known issue here? I've had transient problems with that command as well. Sometimes it works, sometimes it doesn't. 🤷♂️ I'll update the template with the above issue. |
Well then, no worries. I updated the NuGet issue. Thanks for your help! |
OK cool... I wanted to verify here that you were able to get to the preview build. If the Package Manager Console command doesn't work, you can put in the preview feed manually in the NuGet interface and that should work for you. My motivation here is that, if possible, I would prefer to get confirmation from you with the preview build before deploying it to NuGet. :) |
I wanna throw my three cents here. I have my serializer set up like this, because I need a specific date format: IExtendedXmlSerializer serializer = new ConfigurationContainer()
.Type<DateTime>()
.Register()
.Serializer()
.ByCalling((writer, date) => writer.Content(date.ToString("yyyy-MM-dd")), null)
.Create(); But while serializing a class like below I found disappointing result when using nullables: class Test
{
public DateTime Date1 { get; } = DateTime.Now; // Formatted OK
public DateTime? Date2 { get; } = null; // Is not emitted = OK
public DateTime? Date3 { get; } = DateTime.Now; // Completety ignores configured formatting
} I thought "Okay, this is probably my fault, this library might be very type-strict and I need to define a serializer for nullable IExtendedXmlSerializer serializer = new ConfigurationContainer()
.Type<DateTime>()
.Register()
.Serializer()
.ByCalling((writer, date) => writer.Content(date.ToString("yyyy-MM-dd")), null)
.Type<DateTime?>()
.Register()
.Serializer()
.ByCalling((writer, date) => writer.Content(date?.ToString("yyyy-MM-dd") ?? ""), null)
.Create(); And guess what? I believe custom serializer set up for |
Doh are you saying this is occurring with the preview build @ensisnoctis or is this from using the current NuGet release (3.4.2)? We do not provide any sophisticated registration but that error does seem suspicious. I will look into it for you. |
@Mike-E-angelo I can now confirm that version 3.4.2.1-xufywhoa is fixing this issue. |
Great, thank you for the update, @feO2x! @ensisnoctis I took a look into your scenario and with the preview build above I was able to confirm that it works as expected with the following test: home/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue477Tests_Extended.cs Lines 11 to 39 in 431c00e
Do note that I had to modify your If you are still encountering problems, please open up a new issue with a verifiable test that demonstrates a failure and I will look into it further for you. As for registrations, I agree that having to register for both structures and nullable structures is a bit burdensome. I would recommend creating an extension method for this that allows for two commands in one. If you do create something that you feel would be of value please create a PR and we can discuss on integrating into the repro for a future release. 👍 |
Alrighty, this has been deployed to NuGet: https://www.nuget.org/packages/ExtendedXmlSerializer/ Please do let me know of any further issues you encounter and I will take a look into it for you. Closing this issue for now.
|
We've successfully used ExtendedXmlSerializer in one of our projects with quite a complicated object graph. During testing, I found another issue that might be a bug. Please consider the following minimal, complete, verifiable example (MCVE):
In the example above,
Point
is implemented as an immutable struct. When I use this struct as a regular property in a class (as can be seen in classA
), everything works fine. When I use it as aPoint?
, then the corresponding value is deserialized as (0,0) instead of (24, 7). On theIExtendedXmlSerializer
instance,EnableParameterizedContentWithPropertyAssignments
is configured among some other settings (but I don't think they are the cause of this behavior).I suspect that when the XML is deserialized as
Point?
, the default object initializer of the struct is called instead of the constructor that takes two arguments. Might this be the case? Or did I miss something when configuring the serializer?Thank you so much for your help in advance!
The text was updated successfully, but these errors were encountered: