bizzabo / play-json-extensions

+22 field case class formatter and more for play-json
http://cvogt.org/play-json-extensions/api/
Other
196 stars 44 forks source link

could not find implicit value for parameter helper: ai.x.play.json.OptionValidationDispatcher[List[A]] #89

Open mandoolala opened 3 years ago

mandoolala commented 3 years ago

This is my code:

case class ClassA(a:String, b:String …) // >22 case classes

object ClassA {
   implicit val classAJsonFormat = Jsonx.formatCaseClassUseDefaults[ClassA]
}

case class ClassB(classAlist: List[ClassA] = List(), a:String, b: String …) // >22 case classes

object ClassB {
   implicit val classBJsonFormat = Jsonx.formatCaseClassUseDefaults[ClassB]
}

I get compilation error with the message:

could not find implicit value for parameter helper: play.api.libs.json.Reads[List[A]]
TRIGGERED BY: could not find implicit value for parameter helper: ai.x.play.json.OptionValidationDispatcher[List[A]]
TO SOLVE THIS
1. Make sure there is a Reads[List[A]] or Format[List[A]] in the implicit scope
2. In case of Reads[Option[...]] you need to either
   import ai.x.play.json.implicits.optionWithNull // suggested
   or
  import ai.x.play.json.implicits.optionNoError // buggy play-json 2.3 behavior
3. In case of Reads[... .type]
   import ai.x.play.json.SingletonEncoder.simpleName
   import ai.x.play.json.implicits.formatSingleton
   implicit lazy val jsonFormat = Jsonx.formatCaseClassUseDefaults[B]

I have read the related issues (ex. #58) and tried to use formatSealed CompositeClassJsonFormat etc., but nothing seems to work. T^T

scala 2.12.10, play-json 2.8.1, play-json-extensions 0.10.0