You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Version
LiteDB version 5.0.12 / Windows 11 / .Net framework 4.7
Describe the bug
When serializing a derived class as the base class type it gets serialized as the derived type.
Code to Reproduce
class BaseClass
{
public int A { get; set; }
}
class DerivedClass : BaseClass
{
public int B { get; set; }
}
[Fact]
public void Serialize_covariant_type_uses_type_parameter()
{
var derived = new DerivedClass()
{
A = 1,
B = 2,
};
var mapper = new BsonMapper();
var docA = mapper.Serialize<BaseClass>(derived);
var docB = mapper.Deserialize<DerivedClass>(docA);
Assert.True(docB.B == 0); // expected == 0, actual == 2
}
Expected behavior
The expected would be 0 in the above assert, but is actually 2. This is because the mapper reflects on the input object and not the type parameter when serializing.
The text was updated successfully, but these errors were encountered:
Version
LiteDB version 5.0.12 / Windows 11 / .Net framework 4.7
Describe the bug
When serializing a derived class as the base class type it gets serialized as the derived type.
Code to Reproduce
Expected behavior
The expected would be 0 in the above assert, but is actually 2. This is because the mapper reflects on the input object and not the type parameter when serializing.
The text was updated successfully, but these errors were encountered: