Custom Instant BSON Format in ReactiveMongo

78 Views Asked by At

In ReactiveMongo, a default java.time.Instant bson format is provided in the DefaultBSONHandlers class.

I have a trait in which I define my custom format for Instant (toEpochMilliSafe is an extension method for Instant):

trait BSONFormat {
  implicit object InstantWriter extends BSONWriter[Instant] {
    override def writeTry(t: Instant): Try[BSONValue] = Try(BSONDateTime(t.toEpochMilliSafe))
  }
}

Then I create a BSONDocument in a class that inherits from BSONFormat:

BSONDocument(AlertSchedulesSchema.timedTriggerTime -> BSONDocument("$gte" -> from)

But the serialization of 'from' to bson uses DefaultBSONHandlers implemention instead of mine. Is there a way to force it to use my implementation?

0

There are 0 best solutions below