将大 POJO 转换为大小写 class
Converting big POJO to case class
现在我正在将遗留 Java 项目迁移到 Scala。
我遇到了以下问题:我调用 returns java.util.List<SomePojo>
的远程服务。 SomePojo
class 包含大约 50 个字段,我很感兴趣将其以 JSON 格式传递给 UI 的最佳做法是什么。
我正在使用 scalatra 框架,它很好,但是如何将此 POJO 放入 case class 而 case classes 仅限于 21 个字段?或者有更好的方法吗?
这是 Scala 2.11 中的 fixed。
如果您不能使用 2.11,请将字段拆分为单独的大小写 类,然后将它们合并为一个集合。
case class Part1(a: Int, b: Int, c: Int)
case class Part2(d: Int, e: Int, f: Int)
case class Aggregate(part1: Part1, part2: Part2)
val aggregate = Aggregate(Part1(0, 1, 2), Part2(3, 4, 5))
aggregate match {
case Aggregate(Part1(a, b, c), Part2(d, e, f)) =>
}
现在我正在将遗留 Java 项目迁移到 Scala。
我遇到了以下问题:我调用 returns java.util.List<SomePojo>
的远程服务。 SomePojo
class 包含大约 50 个字段,我很感兴趣将其以 JSON 格式传递给 UI 的最佳做法是什么。
我正在使用 scalatra 框架,它很好,但是如何将此 POJO 放入 case class 而 case classes 仅限于 21 个字段?或者有更好的方法吗?
这是 Scala 2.11 中的 fixed。
如果您不能使用 2.11,请将字段拆分为单独的大小写 类,然后将它们合并为一个集合。
case class Part1(a: Int, b: Int, c: Int)
case class Part2(d: Int, e: Int, f: Int)
case class Aggregate(part1: Part1, part2: Part2)
val aggregate = Aggregate(Part1(0, 1, 2), Part2(3, 4, 5))
aggregate match {
case Aggregate(Part1(a, b, c), Part2(d, e, f)) =>
}