scala – 为超过22个字段的案例类播放json合并格式
发布时间:2020-12-16 08:52:01 所属栏目:安全 来源:网络整理
导读:我试图将格式拆分为多个元组,因此它可以处理案例类中超过22个字段.但是,我收到错误“值,并且不是play.api.libs.json.Format的成员”.如何合并案例类的多种格式? val fields1to2: Format[(Int,String)] = ( (__ "a").format[Int] and (__ "b").format[St
我试图将格式拆分为多个元组,因此它可以处理案例类中超过22个字段.但是,我收到错误“值,并且不是play.api.libs.json.Format的成员”.如何合并案例类的多种格式?
val fields1to2: Format[(Int,String)] = ( (__ "a").format[Int] and (__ "b").format[String] ).tupled val fields3to4: Format[(Boolean,List[Int])] = ( (__ "c").format[Boolean] and (__ "d").format[List[Int]] ).tupled implicit val hugeCaseClassReads: Format[Huge] = ( fields1to2 and fields3to4 // "value and is not a member of play.api.libs.json.Format" ) { case ((a,b),(c,d)) => Huge(a,b,c,d) } 解决方法
如果您不仅限于使用Play-JSON,请尝试使用
Play-Json extensions库:
import ai.x.play.json.Jsonx implicit val hugeCaseClassReads: Format[Huge] = Jsonx.formatCaseClass 但是一个更方便,安全和有效的选择将使用jsoniter-scala – 它已经建立了对具有大量字段的案例类的支持. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |