4

Our application uses Play, ReactiveMongo Scala driver and Mongo DB. We have the following versions of these components:

  • com.typesafe.play %% play-json % 2.5.18
  • com.typesafe.play %% play % 2.5.18
  • com.typesafe.play %% play-ws % 2.5.18
  • org.reactivemongo %% play2-reactivemongo % 0.20.3-play25
  • org.reactivemongo %% reactivemongo-play-json % 0.20.3-play25
  • org.reactivemongo % reactivemongo-bson_2.11 % 0.20.3
  • org.reactivemongo %% reactivemongo % 0.20.3

There is a JSON object in MongoDB that looks like this:

“status” : { “siteStatus” : “InProgress”, "timestamp" : NumberLong(“1585696318513”), “timestampLocalDateTime” : “2020-03-31T23:11:58” }

When our application tries to read this object, we get this error: JsResultException(errors:List((,List(ValidationError(List(error.expected.jsnumber),WrappedArray())))))

The attribute that is causing this error is: “timestamp” : NumberLong(“1585696318513”). Play Framework expects it to be in this format: “timestamp” : “1585696318513” but Mongo DB stores it by adding some additional type information which they call Extended-JSON.

The Scala class corresponding to this JSON is:

case class Status(siteStatus: SiteStatus, timestamp: Long, timestampLocalDateTime: Option[LocalDateTime] = None, msg: Option[String] = None)

object Status {
implicit val format: OFormat[Status] = Json.format[Status]
}

We never had any issues parsing this JSON when we were using the older version of play-reactiveMongo library:

“org.reactivemongo” %% “play2-reactivemongo” % “0.12.4”

This error only started happening after upgrading to “play2-reactivemongo” % “0.20.3-play25”. Any work arounds? Please help.

Thank you.

polestar
  • 41
  • 2

0 Answers0