0
我想制作不同我自己的列表类型(即Group,GroupView,GroupItemsView)的通用JSON序列化程序。所以,我定义这三个Json.FormatScala Universal Serializer PlayFramework
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我定义特定的列表类型的作品。它不想使用任何类型。错误如下:
No Json serializer found for type Any. Try to implement an implicit Writes or Format for this type.
如何使PlayFramework斯卡拉JSON序列与我喜欢的类型普遍工作?
谢谢它解决了我的问题!我完全忘记了类型参数化。 – 2014-09-24 11:24:53
另外,请注意Json已经为Lists提供了一个编写器,因为您拥有case类的编写器,所以除非您打算为groupViewToJson函数添加更多功能,否则可以使用它。 – 2014-09-24 11:27:27