我将使用“隐式val reads”来映射Json,如下所示:
:
{
"id": 1
"friends": [
{
"id": 1,
"since": ...
},
{
"id": 2,
"since": ...
},
{
"id": 3,
"since": ...
}
]
}
转换为一个case类
case class Response(id: Long, friend_ids: Seq[Long])
我只能使用一个中间类来反映JSON friends
结构,才能让它正常工作。但我从未在我的应用程序中使用过它。有没有一种方法可以编写一个 Reads [Response]
对象,使我的 Response 类直接映射到给定的JSON?
case class Response(id: Long, friends: Seq[Friend])
这样的东西吗? - mfirryFriend
类。我只需要他们的ID。 - roman-roman