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 the 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]]
import argonaut.EncodeJson._
. No? – Hiura