-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Unknown
-
Affects Version/s: 3.0.0
-
Component/s: Serialization
-
None
-
Fully Compatible
-
Dotnet Drivers
-
Not Needed
-
None
-
None
-
None
-
None
-
None
-
None
Summary
In our database we need to use "type" instead of "_t" for setting type discriminator. We have so far successfully done this with this code during start-up:
BsonSerializer.RegisterDiscriminatorConvention(typeof(JsonTypedObject), new ScalarDiscriminatorConvention("type"));
All of our types that are serialized in this way inherit from "JsonTypedObject". In version 3 of the MongoDB C# Driver running the above code no longer has any effect on the serialization output ("_t" is still used as the discriminator element name).
I have tried to find alternative ways of registering this, but so far I have not had any success. Manually registering all classes individually is not an alternative, as we have hundreds of classes.
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).
How to Reproduce
Repository that shows reproducible example: jizc/mongodb-discriminator-convention-issue
Additional Background
I believe that this commit is what caused the issue: CSHARP-5286: Add IHierarchicalDiscriminatorConvention and IScalarDisc... - mongodb/mongo-csharp-driver@f54ba02
If you don't see this as a bug, please help us by providing an alternative way for us to achieve the "type" discriminator element name.
- is depended on by
-
CSHARP-5413 Custom DiscriminatorConventions not recognized for de/serialization after update to Driver 3.0
-
- Closed
-
- is duplicated by
-
CSHARP-5413 Custom DiscriminatorConventions not recognized for de/serialization after update to Driver 3.0
-
- Closed
-