Description
I need to take a JSON string that came out of JSON.NET and read it into a BsonDocument.
Expected: the BsonDocument will contain an ISODate
Observed: the BsonDocument treats the date as a string
Here's a quick repro that illustrates what I'm seeing:
public void SerializeDates()
|
{
|
var now = DateTime.Parse("2018-04-01T23:43:24.1234567-04:00", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);
|
var obj = new {now};
|
var json = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
|
var bsonFromJson = BsonDocument.Parse(json);
|
var bson = obj.ToBsonDocument();
|
Console.WriteLine("JSON : {0}", json); // prints {"now":"2018-04-02T03:43:24.1234567Z"}
|
Console.WriteLine("BSON from JSON: {0}", bsonFromJson); // prints { "now" : "2018-04-02T03:43:24.1234567Z" }
|
Console.WriteLine("BSON : {0}", bson); // prints { "now" : ISODate("2018-04-02T03:43:24.123Z") }
|
}
|