I have a parametrized case class CaseClass[T](name: String, t: T)
for which I would like to have serialization/deserialization using play-json (2.5).
Of course, I cannot have this if I do not have the equivalent for the type T
, so I define
object CaseClass {
implicit def reads[T: Reads] = Json.reads[CaseClass[T]]
}
But I get the following compiler error:
overloaded method value apply with alternatives:
[B](f: B => (String, T))(implicit fu: play.api.libs.functional.ContravariantFunctor[play.api.libs.json.Reads])play.api.libs.json.Reads[B] <and>
[B](f: (String, T) => B)(implicit fu: play.api.libs.functional.Functor[play.api.libs.json.Reads])play.api.libs.json.Reads[B]
cannot be applied to ((String, Nothing) => CaseClass[Nothing])
If I try to do the same with the Json.writes
macro, I get the error
type mismatch;
found : CaseClass[Nothing] => (String, Nothing)
required: CaseClass[T] => (String, T)
What is most surprising, is that neither error occur when I use the Json.format
macro.
I know I have different solutions to by-pass this problem (using Json.format
, writing my (de)serializer by hand, ...), but I'm rather curious about why this can occur here.