-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 1.0
-
Component/s: None
-
None
Suppose you have the following interface and class:
public interface I {
int X
}
public class C : I {
public ObjectId Id { get; set; }
public int X
{ get; set; }}
If you insert an instance of C using the interface as the nominal type:
var c = new C
{ X = 1 };
collection.Insert<I>(c);
The serializer adds a _t discriminator, so the inserted document looks like:
{ "_id" : ObjectId("4df615dce447ad9c44335d73"), "_t" : "C", "X" : 1 }but a subsequent attempt to read this document back using the interface as the nominal type fails:
collection.FindOneAs<I>();
with the exception: "No serializer found for type TestDeserializeInterface.I.".
While it is true that deserialization must always be to an instance of a concrete class, in this case the deserializer should be able to figure out which concrete class to use by looking at the discriminator value.