Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Salat Sandbox
$ sbt run
[warn] there were 1 deprecation warning(s); re-run with -deprecation for details
[warn] there were 1 feature warning(s); re-run with -feature for details
[warn] two warnings found
[info] Running noahlz.SalatSandbox
null
{
"name":"A",
"datums":[1.0,2.0,3.0]
}
{
"name":"B",
"datums":[0.0,0.0,0.0]
}
Data(C,Vector(NaN, NaN, NaN))
MaybeData(C,Vector(null, null, null))
Datum(Some(NaN))
[success]
package noahlz
import com.novus.salat._
import com.novus.salat.global._
import com.novus.salat.grater
import scala.util.control.NonFatal
case class Data(name: String, datums: Vector[Double])
case class MaybeData(name: String, datums: Vector[Option[Double]])
case class Datum(d: Option[Double])
object SalatSandbox extends App {
private def nullify: Double = {
val x: Null = null
println(x)
x.asInstanceOf[Double]
}
private def printJson(data: Data) =
println(grater[Data].toPrettyJSON(data))
val someData = Data("A", Vector[Double](1.0,2.0,3.0))
val d = nullify
val nullData = Data("B", Vector[Double](d, d, d))
printJson(someData)
printJson(nullData)
val json = """{ "name" : "C", "datums" : [null, null, null] }"""
val datum = """{ "d" : null }"""
try {
val fromJson = grater[Data].fromJSON(json)
println(fromJson)
val maybeFromJson = grater[MaybeData].fromJSON(json)
println(maybeFromJson)
val oops = grater[Datum].fromJSON(datum)
println(oops)
} catch {
case NonFatal(e) => println(e)
}
}
import sbt._
import sbt.Keys._
object BuildSettings {
val scalaVersion = "2.10.2"
val buildVersion = "0.1-SNAPSHOT"
}
object Dependencies {
val Salat = "com.novus" %% "salat" % "1.9.9"
}
object SalatSandboxBuild extends Build {
lazy val SalatSandBox = Project(
id = "salat-sandbox",
base = file("."),
settings = Project.defaultSettings ++ Seq(
name := "salat-sandbox",
organization := "noahlz",
version := BuildSettings.buildVersion,
scalaVersion := BuildSettings.scalaVersion,
libraryDependencies ++= deps,
shellPrompt := ShellPrompt.buildShellPrompt
)
)
import Dependencies._
val deps = Seq(Salat)
}
@noahlz

This comment has been minimized.

Show comment Hide comment
@noahlz

noahlz Oct 8, 2014

Related: novus/salat#113

Owner

noahlz commented Oct 8, 2014

Related: novus/salat#113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment