Issue deserializing a date represented as a string in document from Cosmos DB


Author: Joe Ricklefs

Originally Sourced from: https://stackoverflow.com/questions/68457008/issue-desacralizing-a-date-represented-as-a-string-in-document-from-cosmos-db

I currently have a C# application that queries Cosmos DB. In the database everything is stored as strings. When I query the container for the document and pull out the information it looks like the deserialization process is treating it like a date and its applying the Date Time Offset. Strange part is this process of querying the DB never converts it to a date? I would like it to just pass through the app as its stored in Cosmos.

Here is the document shape in Cosmos:

{
   "id": "uniqueId",
   "MyDate" : "2021-07-24T23:59:00+0000"
}

Here is the code that connects to CosmosDB

using(var client = new CosmosClient("EndPoint","Key")
{
      string sqlQueryText = "Select * From c Where .... ";
      QueryDefinition querySQL = new QueryDefination(sqlQueryText);
      var container = client.GetContainer("databaseId", "ContainerId");
      var iii = container.GetItemQueryIterator<Document>(querySQL);
      
      var myList = new List<Document>();

      while(iii.HasMoreResults)
      {
          FeedResponse<Document> currentRS = iii.ReadNextAsync().Result;

          foreach(Document doc in currentRS)
          {
              myList.Add(doc);
          }
      }
} 

Here is the Output of the this process in C#, By output I mean if you look at the myList Object and inspect the Mydate Property you will see this string below.

"07/24/2021 19:59:00"    

which is the date & time with the date time offset.

How do I prevent this?

This application should just pass the string straight through with no regard for "Real Type".

I would just like to get "2021-07-24T23:59:00+0000"