flink-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Ertl <peter.e...@gmx.net>
Subject json mapper
Date Thu, 03 Aug 2017 10:41:36 GMT
Hi flink users,

I just wanted to ask if this kind of scala map function is correct?

object JsonMapper {
  private val mapper: ObjectMapper = new ObjectMapper()

class JsonMapper extends MapFunction[String, ObjectNode] {
  override def map(value: String): ObjectNode = JsonMapper.mapper.readValue(value, classOf[ObjectNode])

Is using a static reference to ObjectMapper fine or will this cause issues on a distributed
cluster / with checkpoint / serializing state / whatever ?

Or should I instead use a non-transient property initialized in ctor (ObjectMapper is java.io.Serializable)

Or should I initialize it with RichMapFunction.open into a transient property?

Also I am wondering if replacing 'class' with 'object' (=> singleton)

object JsonMapper extends MapFunction[String, ObjectNode] { /* ..*/ }

is ok (actually the mapper is stateless so no obvious need to re-instantiate it again and
again ? )

Thanks and best regards
View raw message