对具有22个以上属性的对象进行json解析
我在scala中使用spray json库进行json格式设置。我按照说明使用如下自定义类型构建jsonformatter:对具有22个以上属性的对象进行json解析,json,scala,parsing,spray-json,Json,Scala,Parsing,Spray Json,我在scala中使用spray json库进行json格式设置。我按照说明使用如下自定义类型构建jsonformatter: class Listing(val attr1:String, val attr2:String, ... val attr35:String) object MyJsonProtocol extends DefaultJsonProtocol { implicit ob
class Listing(val attr1:String,
val attr2:String,
...
val attr35:String)
object MyJsonProtocol extends DefaultJsonProtocol {
implicit object ListingJsonFormat extends RootJsonFormat[Listing] {
def write(l: Listing) =
JsArray(
JsString(l.attr1),
JsString(l.attr2),
...
JsString(l.attr35))
def read(value: JsValue) = value match {
case JsArray(Vector(
JsString(attr1),
JsString(attr2),
...
JsString(attr35))) =>
new Listing(attr1, attr2, attr3, ..., attr35)
case _ => deserializationError("Listing expected")
}
}
}
import MyJsonProtocol._
val json = Listing("red","dress","polka dot", ..., "clothing").toJson
val listing = json.convertTo[Listing]
但是,我遇到了以下错误:
错误:unapply模式的参数太多,最大值=22
有没有一种方法可以解析和格式化超过22个json属性?试试看-它支持一个case类超过10K个字段
这是一本书
此外,该库具有出色的性能特点,下面是使用JDK 8将其与Jackson、Circe和Play JSON库进行比较的基准测试结果:您可以使用该库-它使用Scala宏为您创建JSON格式
下面是包含22个以上字段的案例类的示例:
您有固定大小属性列表的Json吗
35
?你的输入是什么,?