【发布时间】:2014-09-24 19:24:00
【问题描述】:
我想制作我自己的不同列表类型(即 Group、GroupView、GroupItemsView)的通用 JSON 序列化器。所以,我定义了所有三个 Json.Format
implicit val groupsFormat = Json.format[Group]
implicit val groupsViewFormat = Json.format[GroupView]
implicit val groupsItemsViewFormat = Json.format[GroupItemsView]
我的函数应该序列化不同的列表项:
def groupViewToJson(entityList: List[Any]): JsValue = {
val jsonList = Json.toJson(
entityList.map( m => Json.toJson(m))
)
jsonList
}
它仅在我为 entityList 定义特定列表类型时才有效。它不想使用 Any 类型。错误如下:
No Json serializer found for type Any. Try to implement an implicit Writes or Format for this type.
如何让 PlayFramework Scala JSON Serializer 普遍适用于我的类型?
【问题讨论】:
标签: json scala playframework-2.0