Search code examples
mongodbmongodb-.net-driver

Mongo c# difference between implementing IBsonDocumentSerializer and registering BsonClassMap


The Title says it all

I'm trying to custom serialize a POCO that looks like this

public class myClass{
 anotherClass entity
 List<averydifferentclass> entities
 String Group
 String SubGroup
}

each of the above properties will need separate custom mapping/serialization

What's the best way to do this?

Thanks


Solution

  • Start with a BsonClassMap first. It will fit a vast majority of use cases: http://mongodb.github.io/mongo-csharp-driver/2.0/reference/bson/mapping/.

    If you need more power, then implement IBsonDocumentSerializer, but that is relatively complex to get right for all the edge cases.