scalaliftdatabricksazure-databricks

Databricks Scala net.liftweb.json parse() cannot initial error


I can't find anything else relevant on the web. I tried this with both versions of lift 2.12 & 2.10

My cluster/notebook is in apache spark 2.3 & scala 2.11

this code

import net.liftweb.json.DefaultFormats
import net.liftweb.json._
​
val s = """{"steve":"toby"}"""
val j = parse(s)

​ this error

java.lang.NoClassDefFoundError: Could not initialize class net.liftweb.json.package$

Any help appreciated. I can't find any positive way to affect this.


Solution

  • I have added libraryDependencies += "net.liftweb" %% "lift-json" % "3.3.0"

    Below is the same code

     import net.liftweb.json._
     val s = """{"steve":"toby"}"""
     val j = parse(s) //j: net.liftweb.json.JValue = JObject(List(JField(steve,JString(toby))))
    

    Are you missing net.liftweb.json._ here because there is two json literal one for object one for package so we have to use package one. Let me know if this helps.

    Edit

    To add liftweb-json in databricks you have to go to "workspace->create-> Library->[select source] as maven then search packages and add after that restart the cluster and then try to run your notebook.

    And then try to run the below code

    package example
    import net.liftweb.json._
    import org.apache.spark._
    object BasicParseJson {
    def main(args: Array[String]) {
    val s = """{"steve":"toby"}"""
    val j = parse(s)
    // try to log your j value and check
    }
    }