Skip to content

Instantly share code, notes, and snippets.

@yangbajing
Last active August 29, 2015 14:20
Show Gist options
  • Save yangbajing/30aac5d50abda073ae44 to your computer and use it in GitHub Desktop.
Save yangbajing/30aac5d50abda073ae44 to your computer and use it in GitHub Desktop.
Play Json: Json.writes[T] 和 Json.obj 对 Option 的处理不一致
import org.scalatest.{ShouldMatchers, FunSpec}
import play.api.libs.json.Json
case class A(a: String, b: Option[String], c: Option[Int])
class PlayJsonTest extends FunSpec with ShouldMatchers {
implicit val __aWrites = Json.writes[A]
val result = """{"a":"a","c":1}"""
describe("PlayJson") {
it("writes") {
val a = Json.toJson(A("a", None, Some(1)))
Json.stringify(a) shouldBe result
}
it("obj") {
val a = Json.obj("a" -> "a", "b" -> Option.empty[String], "c" -> 1)
Json.stringify(a) shouldBe result
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment