I'm trying to make work a very simple example of Salat.
build.sbt:
libraryDependencies += "com.novus" %% "salat" % "1.9.9"
In sbt console:
import com.novus.salat._
import com.novus.salat.global._
import com.mongodb.casbah.Imports._
case class Alpha(x: String)
val a = Alpha(x = "Hello world")
val dbo = grater[Alpha].asDBObject(a) // not working
The last line throws an exception:
GRATER GLITCH - unable to find or instantiate a grater using supplied path name
REASON: Very strange! Path='Alpha' from pickled ScalaSig causes ClassNotFoundException
Context: 'global'
Path from pickled Scala sig: 'Alpha'
I can't figure out what's wrong, after 2 hours of looking at examples on the internet I couldn't find one that I could make work. Are they all outdated or am I wrong somewhere in my example?
SBT interfere Salat's way of loading class somehow and it's unable to find your class with its default classloader. Test the code not in sbt console, but create a simple project and run it.
UPDATE: as Thomas pointed out Salat needs case class to be compiled and be on classpath to be able to load it.
build.sbt:
libraryDependencies += "com.novus" %% "salat" % "1.9.9"
HelloWorld.scala:
import com.novus.salat._
import com.novus.salat.global._
case class Alpha(x: String)
object HelloWorld {
def main(args: Array[String]): Unit = {
val a = Alpha(x = "Hello world")
val dbo = grater[Alpha].asDBObject(a)
println(dbo.toString)
}
}