Hello!
I have problem with my generic type.
I have some classes like:
I have trait
trait MyClass[A] {
def data: String
}
Also, a few classes:
class SomeClass1 private (val data: String) extends AnyVal with MyClass[SomeClass1]
class SomeClass2 private (val data: String) extends AnyVal with MyClass[SomeClass2]
I want to define JsonWriter for MyClass . But I don't understand how to specify the correct definition. I have one simple test:
def f[A <: MyClass[A]](t: MyClass[A]): Unit = {
println(toJson(t))
}
But it doesnt compile, because:
Cannot find JsonWriter or JsonFormat type class for my.package.MyClass[A]
I defined json writer:
implicit val myClassWriter = new JsonWriter[MyClass[_]] {
override def write(myClass: MyClass[_]): JsValue = {
myClass.data.toJson
}
}
It looks wrong, but I don't understand how to solve the problem.