Last active
August 29, 2015 14:20
-
-
Save yangbajing/30aac5d50abda073ae44 to your computer and use it in GitHub Desktop.
Play Json: Json.writes[T] 和 Json.obj 对 Option 的处理不一致
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 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