Search code examples
scalajson4s

json4s error when using DefaultFormats


I'm trying to use json4s to simply deserialize a list of object from json.

However I'm always getting an error when setting the formats:

java.lang.ClassNotFoundException

In instance

import org.json4s.DefaultFormats
import org.json4s.jackson.JsonMethods.parse

class Deserializer {
  implicit val formats = DefaultFormats

  def desSubc(input : String) : List[String] = {
    val json = parse(input)
    json.extract[List[String]]
  }
}

I'm getting this when object is created:

java.lang.ClassNotFoundException

I'm working with scala 2.12.3 and json4s-jackson_2.11 3.5.3

Any ideas?


Solution

  • It's hard to say for certain without the class that's missing, but it's likely because you're using json4s compiled for Scala 2.11, not Scala 2.12.

    Make sure you're using the right dependency version (the _2.XX in the json4s jar name).