0

Trying to convert Apache Flink Source String to Map using scala.

My Source Streaming String : key1=value1key2=2000-12-17 00:00:00key3=Testkey4=08.89198key5=103.000

Code :

val environment = StreamExecutionEnvironment.getExecutionEnvironment
val out  = environment.addSource(...)
val mapper = new ObjectMapper()
val texToMap = out.map(mapper.readValue(_,classOf[Map[Object,Object]])
println(textToJson)

Its throwing error like

org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'key1': was expecting ('true', 'false' or 'null')

Is there any way to transform the String value to Map since i'm new to flink implementation.

Thirunavukkarasu
  • 361
  • 1
  • 2
  • 13

1 Answers1

1

Apache Flink uses jackson shaded jar for some special uses. In your case, you need to import com.fasterxml.jackson.databind.ObjectMapper instead of Flink's shaded jackson dependency.
And at the same time, you need this because you're using Scala.

import com.fasterxml.jackson.module.scala.DefaultScalaModule
val mapper = new ObjectMapper()
mapper.registerModule(DefaultScalaModule)
Jiayi Liao
  • 999
  • 4
  • 15