kmongo icon indicating copy to clipboard operation
kmongo copied to clipboard

[Feature] Support kotlinx.datetime values

Open rocketraman opened this issue 3 years ago • 4 comments

I am using kmongo on a multiplatform project, which necessarily uses kotlinx.datetime for the datamodel since java.time.* are not multiplatform.

It would be great if kotlinx.datetime was supported for serializing date/times by default.

rocketraman avatar Mar 01 '22 14:03 rocketraman

Not sure how similar this is, but I've been trying to use mongo 5.0 time-series collections, with kotlinx.serialization and kotlinx.datetime. In a regular collection I can use kotlinx.datetime with no issue but if I try to use it for the time series field of a time series collection I get the following error : WriteError{code=2, message=''timestamp' must be present and contain a valid BSON UTC datetime value', details={}}

cholwell avatar May 18 '22 17:05 cholwell

This would help a lot. Seems like kotlinx.serialization serializes dates to strings, therefore I have the same problem on timeseries as @cholwell and when there is data in a collection with dates, I get the following Error when loading the data: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is DATE_TIME.

rkreienbuehl avatar Sep 20 '22 06:09 rkreienbuehl

I just implemented serialization for kotlinx.datetime Instant, LocalDate, LocalDateTime and LocalTime and made a pull-request. The serialization works for normal collections, as well as for time-serie collections.

Are there other serializations needed from kotlinx.datetime?

rkreienbuehl avatar Sep 20 '22 11:09 rkreienbuehl

Thank you! I'm going to review the PR

zigzago avatar Sep 20 '22 20:09 zigzago