【发布时间】:2020-11-15 10:25:59
【问题描述】:
我们有两个具有不同参数的案例类。例如-
case class OneType(@JsonProperty("column1") column1 : String,
@JsonProperty("column2") column2 : Map[String,Any],
@JsonProperty("column3") column3 : Seq[String]
)
case class AnotherType(@JsonProperty("column1") column1 : String,
@JsonProperty("column2") column2 : BigInt,
@JsonProperty("column3") column3 : Map[String,String]
)
这两个案例类将用于反序列化传入的 JSON 消息(通过将它们与案例类映射)。它们需要在另一个类声明中使用。比如——
class JSONDeserialize extends StreamManager(String, Either[Failed, OneType/AnotherType]){
}
如何将适当的案例类(此处为 OneType 或 AnotherType)动态分配给 JSONDeserialize 类,而不会产生重复的 JSONDeserialize 类?
【问题讨论】:
标签: json scala dynamic case-class