If you need to use this ASP.NET kernel for the case when you return the model with BsonDocument, in order to be able to add dynamic data. You can use this JsonConverter implementation based on MarkKGreenway answer!
public class BsonDocumentJsonConverter : JsonConverter { public override bool CanConvert(Type objectType) { return objectType == typeof(BsonDocument); } public override bool CanRead { get { return false; } } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { throw new NotImplementedException(); } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
Then in your Startup.cs just add the following.
services.AddMvc() .AddJsonOptions(options => options.SerializerSettings.Converters.Add(new BsonDocumentJsonConverter()));
source share