case class Foo1(s: String) // Matching names
case class Foo2(s: String)
case class Bar(f: Foo2)
val foo = Foo1("foo") :: HNil
val fooGen1 = LabelledGeneric[Foo1]
val fooGen2 = LabelledGeneric[Foo2]
val barGen = Generic[Bar]
object mapping {
implicit def caseFoo = at[Foo](f => fooGen2.from(fooGen1.to(f)))
}
val bar = barGen.from(foo.map(mapping))
bar == Bar(Foo2("foo"))
有没有办法以通用的方式定义mapping
?使用类型元组列表。
编辑:
我有自动生成的控制器案例类和手动编写的案例类,其中包含我想要放入自动生成的案例类的数据。自动生成的看起来像
case class RequestanAccount200(result: CompaniesCompanyGetBody200ResponseBody)
(implicit val writer: String => Option[Writeable[CompaniesCompanyGetBody200ResponseBody]])
extends RequestanAccountType[CompaniesCompanyGetBody200ResponseBody] { val statusCode = 200 }
case class CompaniesCompanyGetBody200ResponseBody(company: Company)
case class Company(id: String, users: Users)
type Users = Seq[String]
和手动案例类,例如
case class ManualCompany(id: String, users: Seq[String])
据我所知,案例类的含义对于无形无效,因此我认为我将开始在CompaniesCompanyGetBody200ResponseBody
级别生成。我有一个ManualCompany
,我想要一个CompaniesCompanyGetBody200ResponseBody
,最好有最少的样板。