Search code examples
scalaimplicitlift-json

Scala Lift JSON error that is not fixed with normal solution


I have the following Scala project on GitHub. In that repo I have a class, Configurator, whose job it is to read a JSON file's contents into a string, and then use the Lift JSON library to deserialize the string into an instance of an AppConfig:

import scala.io.Source
import net.liftweb.json._

class Configurator {
  def loadConfigs(configFileUri : String) : AppConfig = {
    implicit val formats = net.liftweb.json.DefaultFormats
    parse(Source.fromFile(configFileUri).mkString).extract[AppConfig]
  }
}

If you clone this and then run ./gradlew run you'll get the following exception:

/Users/myuser/intellij-scala-gradle-example/shared/src/main/scala/com/me/myapp/Configurator.scala:9: could not find implicit value for parameter formats: net.liftweb.json.Formats
    parse(Source.fromFile(configFileUri).mkString).extract[AppConfig]

If you Google that exception you'll see 10,000 recommendations for that implicit format fix which I implemented right here. But that did not work for me. So I'm wondering:

  1. Why am I seeing this exception?
  2. What's the fix?

Solution

  • Switched from Lift JSON to GSON and all my problems are gone.