A concrete model class exists with a single dynamic field. This field could contain hundreds of COMPLEX data structures, and we won't be able to know what they are always.
public class Message {
public dynamic MessageData { get; set; }
}
We can save this json from postman:
{
"messageData": {
"sdfghdfghjdfghdfg": {
"sdfgsdfsdfghs": [
{
"dfgfghkfghjfg": "4567456734573",
"dfjghjjkdehn": "fgjfghdfgjfhnfgh"
}
],
"hfgjkfguksdfgnuy": {}
}
}
}
Our mongo find method shows this result:
{
{ "_id" : ObjectId("607605a7d42ba9fa20579745"),
"MessageData" : { "_t" : "Newtonsoft.Json.Linq.JArray, Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed", "_v" : [ { "_t" : "JObject", "_v" : [ { "_t" : "JProperty", "_v" : [ { "_t" : "JObject", "_v" : [ { "_t" : "JProperty", "_v" : [ { "_t" : "JArray", "_v" : [ { "_t" : "JObject", "_v" : [ { "_t" : "JProperty", "_v" : [ { "_t" : "JValue", "_v" : [ ] } ] }, { "_t" : "JProperty", "_v" : [ { "_t" : "JValue", "_v" : [ ] } ] } ] } ] } ] }, { "_t" : "JProperty", "_v" : [ { "_t" : "JObject", "_v" : [ ] } ] } ] } ] } ] } ] }
}
When fetching the data we get this error:
System.FormatException: An error occurred while deserializing the MessageData property of class EMRPatientDB.Models.Message: Invalid element: '_t'.
The problem seems to be the MongoDB C# driver isn't serializing the JSON correctly?
Perhaps we want to write a custom serializer? But I haven't found a good example of how that is done for a JSON object.