Parse JSON Object to Map in Scala Using Jackson

I couldn’t find a good example online, so here it goes.

import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.databind.ObjectMapper

val data = """
    {"some": "json data"}
"""

val mapper = new ObjectMapper

mapper.registerModule(DefaultScalaModule)
mapper.readValue(data, classOf[Map[String, String]])
Code language: PHP (php)

Hope it helps

2 thoughts on “Parse JSON Object to Map in Scala Using Jackson”

  1. Works with Flink Scala Shell v 1.4.2 .

    Got stuck with :

    scala> import com.fasterxml.jackson.databind.ObjectMapper
    import com.fasterxml.jackson.databind.ObjectMapper

    scala> val mapper = new ObjectMapper
    java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.databind.ObjectMapper
    … 30 elided

    for Flink Scala Shell v 1.7.1

Comments are closed.