我有一个简单的自定义数据结构,用于将来自数据库的结果进行映射:
case class Filter(id: Int, table: String, name: String, Type: String, structure: String)
生成的对象类型是
List[Filter]
,如果转换为JSON格式,应该看起来像这样:[
{
"id": 1,
"table": "table1",
"name": "name1",
"Type": "type1",
"structure": "structure1"
},
{
"id": 2,
"table": "table2",
"name": "name2",
"Type": "type2",
"structure": "structure2"
}
]
现在当我尝试将对象序列化为JSON时,
val result: String = Json.toJson(filters)
我收到了类似以下的信息:
No Json deserializer found for type List[Filter]. Try to implement an implicit Writes or Format for this type.
我该如何解决这个看似简单的问题,而不需要写大量的样板代码呢?
我的技术栈是Play 2.2.1、Scala 2.10.3和Java 8 64位。