Vote count:
0
I would like to encode to json a field of type List[E] using argonaut lib.
sealed trait Msg[E] {
val contents: List[E]
def send(): Unit = {
val json = contents.asJson
println("Sending json: " + json.toString())
}
}
Then i have a StringMsg case class:
case class StringMsg(contents: List[String]) extends Msg[String]
The argonaut lib defines a JsonIdentity[J] trait:
trait JsonIdentity[J] {
val j: J
/**
* Encode to a JSON value using the given implicit encoder.
*/
def jencode(implicit e: EncodeJson[J]): Json =
e(j)
}
When i create a new instance of StringMsg and call the send() method, i have the following error:
StringMsg(List("a","b")).send()
could not find implicit value for parameter e: argonaut.EncodeJson[List[E]]
asked 12 secs ago
Implicit encoder for a trait type parameter
Aucun commentaire:
Enregistrer un commentaire