我是Scala + Play的新手。我正在尝试从创建对象mongodb的其他项目中导入代码,但在此之前,代码使用带有隐含的Json验证器。我的对象由两种类型组成:Valunit和CreateDatumRequest。该错误在“隐式val createDatumRequestFmt = Json.format [CreateDatumRequest]”行上,但是说明了上一行中的Valunit对象。
No implicit format for Map[String,Option[nl.amc.ebioscience.rosemary.models.core.Valunit]] available.
@Singleton
class DataController @Inject() (securityService: SecurityService) extends Controller with JsonHelpers {
.....
case class CreateDatumRequest(
name: String,
parent: Option[Datum.Id],
remarks: Option[String],
category: Tag.Id, // Datum Category tag
dict: Map[String, Option[Valunit]]) {
def validate(workspaceId: Tag.Id): Either[String, Map[DefaultModelBase.Id, BaseEntity]] = {
........
}
object CreateDatumRequest {
implicit val valunitFmt = Json.format[Valunit]
implicit val createDatumRequestFmt = Json.format[CreateDatumRequest]
}
......
}
答案 0 :(得分:0)
尝试为dict: Map[String, Option[Valunit]])
定义阅读。您可以在此处阅读更多内容。https://www.playframework.com/documentation/2.5.x/ScalaJsonCombinators#complex-reads