Skip to content

Instantly share code, notes, and snippets.

@andypetrella
Created March 11, 2012 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andypetrella/2016161 to your computer and use it in GitHub Desktop.
Save andypetrella/2016161 to your computer and use it in GitHub Desktop.
Salat and Play 2.0
//...
val novusSnapsRepo = "Novus Snapshots Repository" at "http://repo.novus.com/snapshots/"
val salatCore = "com.novus" %% "salat-core" % "0.0.8-SNAPSHOT" withSources
val salatUtil = "com.novus" %% "salat-util" % "0.0.8-SNAPSHOT" withSources
val appDependencies = Seq(
// Add your project dependencies here,
salatCore,
salatUtil
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
// Add your own project settings here
resolvers ++= Seq(
novusSnapsRepo
)
)
//...
case class Model(_id:ObjectId, data: String = "") {
}
object Model {
// Defining this, ease the usage of the grater, otherwise it implies the user to import himself all Salat deps. Now, we can simply use this val without extra imports.
def graterModel(implicit ctx:Context): Grater[Model] = grater[Model]
def to(m:Model):DBObject= graterModel.asDBObject(m)
def from(m:DBObject):Model = graterModel.asObject(m)
}
package object salatctx {
/**
* Here is where we define the custom Play serialization context, including the Play classloader.
*/
implicit val ctx = {
val c = new Context {
val name = "play-context"
}
c.registerClassLoader(Play.classloader)
c
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment