1
無法解碼集我想這一塊的JSON解碼:在瑟茜
{
"id" : "e07cff6a-bbf7-4bc9-b2ec-ff2ea8e46288",
"paper" : {
"title" : "Example Title",
"authors" : [
"1bf5e911-8878-4e06-ba8e-8159aadb052c"
]
}
}
然而,當它到達了集合的一部分,它的失敗。該錯誤消息沒有幫助。
DecodingFailure([A]Set[A], List())
這裏是我的docoders:
implicit val paperIdDecoder: Decoder[PaperId] = Decoder.decodeString.emap[PaperId] { str ⇒
Either.catchNonFatal(PaperId(str)).leftMap(_.getMessage)
}
implicit val paperAuthorDecoder: Decoder[PaperAuthor] = Decoder.decodeString.emap[PaperAuthor] { str ⇒
Either.catchNonFatal(PaperAuthor(str)).leftMap(_.getMessage)
}
implicit val paperDecoder: Decoder[Paper] = {
for {
title <- Decoder.decodeString
authors <- Decoder.decodeSet[PaperAuthor]
} yield Paper(title, authors)
}
implicit val paperViewDecoder: Decoder[PublishedPaperView] = for {
id <- Decoder[PaperId]
paper <- Decoder[Paper]
} yield PublishedPaperView(id, paper)
這裏使用的情況下類:
case class PublishedPaperView(id: PaperId, paper: Paper)
case class PaperId(value: String)
case class Paper(title: String, authors: Set[PaperAuthor])
case class PaperAuthor(value: String)