I upgraded by Java driver from 3.12.6 to 4.5.0 and there appears to be a difference in how dates are serialized. Previously, serialization would result in a long/number value:
"entryDate": {
"$date": 1646317760029
}
After upgrading to 4.5.0, dates are serialized as an ISO string:
Sure. This code hasn’t changed between driver versions. I have a service that reads from Mongo, converts BSON to a Java JSON, does some manipulation, a returns to a caller. The caller then takes that JSON to does what it needs to do, such as stuff it into a Java-specific object. It’s the bson.toJson() that used to serialize dates as number, but now it’s ISO strings.
Strict Mode: Legacy representation. Though now deprecated, this is still the default mode when writing JSON in order to avoid breaking backwards compatibility. This may change in a future major release of the driver.
That’s obviously not true, because the default (no JsonWriterSettings supplied to the toJson() method) clearly behaves differently from supplying .outputMode(JsonMode.STRICT) .
Either the documentation is wrong, or there is a bug in the driver.
The documentation is wrong. 4.0 was the major release in which we changed the default, but clearly we missed some of the places where the 3.x behavior is still documented.
Looks like the API docs are all updated, but not some of the reference docs. The breaking change is also mentioned in the 4.0 Upgrading Guide, as well.