Kevin Hoffman
Kevin Hoffman

Reputation: 5152

Salat Fails to Serialize in Running Play Framework Application but Works Fine in Console

I have a Play 2.1.0 (Scala) framework application and I am trying to use Salat to convert my case class objects into MongoDBObjects. When I fire up the play console, instantiate one of my case classes, import salat._ and salat.global._ I am able to convert from my case class to a MongoDBObject.

When I am in "run" mode in play, and I invoke a page which invokes Actors which in turn execute the same code to convert from case class to MongoDBObject, I get errors (data.Field is the full name of my case class):

com.novus.salat.util.GraterGlitch:

  GRATER GLITCH - unable to find or instantiate a grater using supplied path

name

  REASON: Very strange!  Path='data.Field' from pickled ScalaSig causes Clas

sNotFoundException

  Context: 'global'
  Path from pickled Scala sig: 'data.Field'

In response to another question here, I added the scala-compiler to my project's dependencies and that didn't help.

What boggles me is that this works fine in the console manually instantiating stuff but fails when running the full play app.

Any help here would be greatly appreciated.

Edit: Adding the scala compiler to the dependencies and using "play start" works fine. If I use "play run", it fails miserably using the above error. Any insight as to why would be helpful.

Upvotes: 2

Views: 829

Answers (1)

yakamoto
yakamoto

Reputation: 50

According to https://github.com/playframework/Play20/issues/822, this is caused by a dynamic classloader.

In my case, this code solved the problem.

implicit val ctx = new Context {
  val name = "Custom_Classloader"
}
ctx.registerClassLoader(Play.classloader(Play.current))

See also https://github.com/novus/salat/wiki/CustomContext

Upvotes: 3

Related Questions