我们是Scala和Apache Flink的新手。当我们尝试使用ObjectMapper [com.fasterxml.jackson.databind.ObjectMapper]将scala.collection.mutable.Map转换为Scala POJO类时,出现无法识别的字段“ sizeMapDefined”异常。
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段“ sizeMapDefined”(com.test.model.Data类),未标记为可忽略
在apache flink的帮助下尝试将AMPS(crankuptheamps)中的数据作为DataStream订阅。
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import scala.beans.BeanProperty
@JsonIgnoreProperties(ignoreUnknown = true)
@SerialVersionUID(123L)
class Data() extends Serializable {
@BeanProperty var name: String = _
@BeanProperty var address: String = _
override def toString = s"Data($name, $address)"
}
@transient lazy val mapper = new ObjectMapper() with Serializable with ScalaObjectMapper
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
mapper.registerModule(DefaultScalaModule)
var map = scala.collection.mutable.Map("name" -> "Thiru",
"address" -> "Mayiladuthurai")
val testClass = mapper.convertValue(map, classOf[Data])