Last active
August 29, 2015 14:07
-
-
Save noahlz/1756e4efec855c030ebe to your computer and use it in GitHub Desktop.
Salat Sandbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related: novus/salat#113