【问题标题】:object BSONDocumentFormat in trait BSONFormats is deprecated: 0.11.9不推荐使用特征 BSONFormats 中的对象 BSONDocumentFormat:0.11.9
【发布时间】:2026-01-06 17:55:02
【问题描述】:

我有一个以下函数,它接收输入 JSON 并使用 "com.eclipsesource" %% "play-json-schema-validator" % "0.6.2" 对照给定的 JSON 架构验证它。在我开始收到有关已弃用库的警告之前,整个设置运行良好。如您所见,我使用Ok(Json.toJson(result)))scala.List[BSONDocument] 类型的result 转换为JSON。这是使用import play.modules.reactivemongo.json.BSONFormats._ 库完成的。我真的很喜欢这种转换的简单性,但是,我收到以下警告:

object BSONDocumentFormat in trait BSONFormats is deprecated: 0.11.9

还有,这是我的实际功能:

def getMessage(campaignID: String, revision: Int, transactionID: Int ) = 
   Action.async { implicit request =>

  db.getDocument(campaignID, revision, transactionID)
  .map(result =>
  Ok(Json.toJson(result)))
  .recover {case ex: IOException => InternalServerError("Please install MongoDB")}

}

有没有其他方法可以做到这一点?为什么库开发者会删除这么有用的功能?

【问题讨论】:

标签: scala playframework reactivemongo play-reactivemongo


【解决方案1】:

根据@cchantep cmets,我能够通过替换来解决问题:

import play.modules.reactivemongo.json.BSONFormats._

与:

import reactivemongo.play.json.BSONFormats._

【讨论】:

  • documentation 中所建议,导入为import reactivemongo.play.json._