home: EnableImplicitTypingFromAll breaks EnableReferences
I’m new to this library so still playing around with how ConfigurationContainer works. Apologies if this is the intended behavior.
Here’s a simplified version of my data structures:
public class MainDTO
{
public SubDTO Sub1 { get; set; } = new SubDTO();
public SubDTO Sub2 { get; set; } = new SubDTO();
public SubDTO Sub3 { get; set; } = new SubDTO();
}
public class SubDTO
{
public SubSubDTO SubSub1 { get; set; } = SubSubDTO.NullObject;
}
public class SubSubDTO
{
public static SubSubDTO NullObject { get; } = new SubSubDTO();
public string Id { get; set; } = Guid.NewGuid().ToString();
}
And here is my container
var serializer = new ConfigurationContainer()
.UseAutoFormatting()
.UseOptimizedNamespaces()
.EnableImplicitTyping(new[] {
typeof(MainDTO), // <-- this causes assertion error
typeof(SubDTO),
typeof(SubSubDTO)
})
.Type<SubSubDTO>()
.EnableReferences(definition => definition.Id)
.Create();
I would expect all SubDTO
objects in MainDTO
to be different objects that hold a reference to the same SubSubDTO
object.
Here is the output
<?xml version="1.0" encoding="utf-8"?>
<SerializerPlayground-MainDTO xmlns="clr-namespace:UnitTests.RecipeTests;assembly=UnitTests">
<Sub1>
<SubSub1 Id="78238952-0d09-48dd-8725-4a7326fa897b" />
</Sub1>
<Sub2>
<SubSub1 xmlns:exs="https://extendedxmlserializer.github.io/v2" exs:entity="78238952-0d09-48dd-8725-4a7326fa897b" />
</Sub2>
<Sub3>
<SubSub1 xmlns:exs="https://extendedxmlserializer.github.io/v2" exs:entity="78238952-0d09-48dd-8725-4a7326fa897b" />
</Sub3>
</SerializerPlayground-MainDTO>
This looks right, at least they reference the correct ids. But when I deserialize it, Sub1
is correct but the other two have new Guids.
I tracked down the culprit to this line:
.EnableImplicitTyping(typeof(MainDTO))
If I take this out, all works as expected.
Another strange thing, if MainDTO
references SubSubDTO directly (instead of the middle object) it works fine, even when enabling implicit typing for all types.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (16 by maintainers)
Hey @Mike-E-wins I’m doing my own reference resolving after deserialization, so I likely won’t come back to this. Just FYI in case you want to close the issue.
Hi @Mike-E-wins , works on my end. Thanks for updating the documentation!
Thanks @Mike-E-wins , that fix worked for me as well. You are awesome!
Two questions for you:
Is there any way to get rid of the
xmlns:exs
namespaces, or at least pull that definition up to theMainDTO
element?exs:entity=id
and other times they useexs:member="" exs:reference="#"
. Curious what the difference is.Thanks again!