2

我有这样的 JSON:

  "data": {
    "project": {
      "activityChildren": [
        {
          "id": 2,
          "parents": [
            {
              "id": 1
            }
          ]
        },

      ]
    }
  }

我想List[(Long, List[Long])]用 circe-optics 将其解码。我做到了:

  val activityParents: Map[Long, List[Long]] = root.data.activityChildren.each.json
      .getAll(json)
      .flatMap { activity =>
        root.id.long.getOption(activity).map(_ -> root.parents.each.long.getAll(activity))
      }
      .toMap

我想知道是否可以为此定义一个镜头,只需将 JSON 转换为所需的映射,而无需显式映射到中间数组。如果是这样,怎么做?

4

0 回答 0