播放Framework Scala格式的大JSON(未找到unapply或unapplySeq函数) [英] Play Framework Scala format large JSON (No unapply or unapplySeq function found)
本文介绍了播放Framework Scala格式的大JSON(未找到unapply或unapplySeq函数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在服务器上接收到一个大型JSON(超过22个字段). 我有一个包含很多字段的案例类:
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] = None,
deal: Option[String] = None,
roomsCount: Option[String] = None,
region: Option[Int] = None,
district: Option[Int] = None,
direction: Option[Int] = None
...
)
并且JSON格式在控制器中起作用:
And JSON format function in controller:
implicit val filtersFormat = Json.format[Filters]
编译时出现错误:
[error] WebSockets.scala:18: No unapply or unapplySeq function found
[error] implicit val filtersFormat = Json.format[Filters]
[error] ^
有没有一种方法可以解决此问题而又不将JSON分成小部分?
Is there a way to solve the problem without breaking JSON to small parts?
推荐答案
我是这样做的:
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))
}
这篇关于播放Framework Scala格式的大JSON(未找到unapply或unapplySeq函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文