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

Broken references deserialization #407

Closed
ondrasvoboda opened this issue Jun 22, 2020 · 10 comments
Closed

Broken references deserialization #407

ondrasvoboda opened this issue Jun 22, 2020 · 10 comments
Assignees
Labels
bug (cc: fix) Something isn't working

Comments

@ondrasvoboda
Copy link

Hi,
after updating to the latest version 3.2.0 I'm unable to deserialize correctly XML created with .EnableReferences() option.

Fragment of my XML file:

    <ns1:Lookuptable xmlns:ns32="clr-namespace:MA.App.Model.Dto.Lookuptables;assembly=MA" exs:arguments="ns32:PathogenDto">
        <Models>
            <Capacity>64</Capacity>
            <ns2:Pathogen>
                <ScientificName>Phellinus igniarius</ScientificName>
                <LocalizedName>Phellinus igniarius</LocalizedName>
                <PathogenType exs:member="" exs:identity="1">
                    <Code>f</Code>
                    <Description>Fungus</Description>
                </PathogenType>
            </ns2:Pathogen>
            <ns2:Pathogen>
                <ScientificName>Pholiota destruens</ScientificName>
                <LocalizedName>Pholiota destruens</LocalizedName>
                <PathogenType exs:member="" exs:reference="1" />
            </ns2:Pathogen>
    </ns1:Lookuptable>
    <ns1:Lookuptable xmlns:ns36="clr-namespace:MA.App.Model.Dto.Lookuptables;assembly=MA" exs:arguments="ns36:PathogenTypeDto">
        <Models>
            <ns2:PathogenType exs:reference="1" />
        </Models>
    </ns1:Lookuptable>

After deserialization I get PathogenType with Code and Description null, instead of "f" and "Fungus". It works in 3.1.4. I've seen some changes regarding references in the last version, so am I missing something or is it a bug?

Thanks!

@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.90. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@issue-label-bot issue-label-bot bot added the bug (cc: fix) Something isn't working label Jun 22, 2020
@Mike-E-angelo
Copy link
Member

Boo... I was afraid of something like this. Thank you for taking the time to report.
Yes, we did do some work with 3.2.0 around references to change how references work in the case of attributes. Although, I am not sure why that would impact you as you do not seem to be using attributes and everything is an element.

Is the above a list? I will attempt to create the object graph and see if I can reproduce this for you. Apologies for breaking your code. 😞 Please use 3.1.4 until we figure this out.

@Mike-E-angelo Mike-E-angelo self-assigned this Jun 22, 2020
@ondrasvoboda
Copy link
Author

Yes, it is a list of lookuptables and each has list of values in Models property. A value sometimes reference value from another lookup table - like in this case Pathogen reference PathogenType which is another lookuptable.
Thanks for looking into it.

@Mike-E-angelo
Copy link
Member

OK cool thank you for the context, @ondrasvoboda. To be sure, your referenced XML above does not have a closing </Models> tag so want to be sure that's due to removing additional data and not a malformed document.

@ondrasvoboda
Copy link
Author

Yes, that's due to removing additional data.

@Mike-E-angelo
Copy link
Member

Alright @ondrasvoboda unfortunately I am not having any luck reproducing this. I am eyeballing the model so there might be something fundamental that I am overlooking here. This is what I have and seems to be passing OK:

[Fact]
public void Verify()
{
var type = new PathogenType{ Code = 'f', Description = "Fungus" };
var instance = new List<object>
{
new LookupTable<PathogenDto>
{
Models = new List<PathogenDto>
{
new Pathogen{ ScientificName = "Phellinus igniarius", LocalizedName = "Phellinus igniarius", PathogenType = type },
new Pathogen{ ScientificName = "Pholiota destruens", LocalizedName = "Pholiota destruens", PathogenType = type }
}
},
new LookupTable<PathogenTypeDto>
{
Models = new List<PathogenTypeDto> { type }
}
};
var serializer = new ConfigurationContainer().EnableReferences().ForTesting();
var cycled = serializer.Cycle(instance);
var expected = cycled[1].To<LookupTable<PathogenTypeDto>>().Models.Only();
var table = cycled[0].To<LookupTable<PathogenDto>>();
table.Models[0].PathogenType.Should()
.BeSameAs(expected);
table.Models[1].PathogenType.Should()
.BeSameAs(expected);
}
sealed class LookupTable<T>
{
public List<T> Models { get; set; } = new List<T>();
}
class PathogenDto
{
public string ScientificName { get; set; }
public string LocalizedName { get; set; }
// ReSharper disable once MemberHidesStaticFromOuterClass
public PathogenTypeDto PathogenType { get; set; }
}
sealed class Pathogen : PathogenDto {}
class PathogenTypeDto {}
sealed class PathogenType : PathogenTypeDto
{
public char Code { get; set; }
public string Description { get; set; }
}

Is there anything that sticks out at you that I am not considering?

@Mike-E-angelo
Copy link
Member

Mike-E-angelo commented Jun 22, 2020

Boom... figured it out. It's our good friend the exs:member="" hack. This does not look promising but I will look into this. Hang tight with 3.1.4 in the meantime.

@Mike-E-angelo
Copy link
Member

Mike-E-angelo commented Jun 22, 2020

Alright @ondrasvoboda check out the instructions here:
#408 (comment)

And see if that treats you better. If it does, I will release this to NuGet ASAP since this will no doubt impact others.

@ondrasvoboda
Copy link
Author

Works great, thanks!

@Mike-E-angelo
Copy link
Member

Mike-E-angelo commented Jun 22, 2020

Awesome! Good news is that as easier than I expected, but bad news is that it involved adding another boolean check to the code which makes it feel hackier. I am very much hoping exs:member="" doesn't make any more appearances, in any case.

Anyways, v3.2.1 is here:
https://www.nuget.org/packages/ExtendedXmlSerializer/

Not complaining about that version number, either! 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug (cc: fix) Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants