Play Framework Scala format large JSON (No unapply or unapplySeq function found)

后端 未结 3 1242
感情败类
感情败类 2021-01-11 15:33

I need to receive a big JSON on my server (more than 22 fields). I have a case class with a lot of fields:

case class Filters(objectType: Option[String] = No         


        
3条回答
  •  攒了一身酷
    2021-01-11 16:05

    I did it this way:

    case class Filters(part1: Part1, part2: Part2, ...)
    
    case class Part1(
        field1: Field1,
        field2: Field2,
        ...
        field10: Field10,
    )
    
    object Part1 {
        implicit val part1Format = Json.format[Part1]
    }
    
    ...
    
    object Filters {
        implicit val filtersReads = (
            JsPath.read[Part1] and
            JsPath.read[Part2] and
            ...
        )(Filters.apply _)
    
        implicit val filtersWrites = (
            JsPath.write[Part1] and
            JsPath.write[Part2] and
            ...
        )(unlift(Filters.unapply))
    }
    

提交回复
热议问题