Expanding on this, if the single field case class were a higher kind such as
case class Foo(foo: List[String])
everything below still works just fine:
(__ \ "foo").read[List[String]].map(Foo(_))
but say you were trying to validate that field with a uniqueitems validation function such as:
def uniqueItems[String](isUnique: Boolean)(implicit tag: TypeTag[String], r: Reads[List[String]]): Reads[List[String]] = {
Reads.of[List[String]].filter(ValidationError(uniqueItemsJsonValidationError))({ items =>
if (isUnique) items.size == items.distinct.size
else true
})
}
which would change the read to
(__ \ "foo").read[List[String]](uniqueItems(true)).map(Foo(_))
giving a compile error as there is no implicit for a List[String] though we know play can deserialize a String:
No Json deserializer found for type List[String]. Try to implement an implicit Reads or Format for this type.
[error] implicit val dinosaurReader: Reads[Dinosaur] = ((JsPath \ "friends").read[List[String]](uniqueItems(true))).map(Dinosaur)