Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ object CustomApply {

case class Optional(props: Option[String])

case class UserId(id: Long) extends AnyVal

class JsonExtensionSpec extends AnyWordSpec with Matchers {
"JsonExtension" should {
"create a reads[User]" in {
Expand Down Expand Up @@ -749,5 +751,19 @@ class JsonExtensionSpec extends AnyWordSpec with Matchers {
formatter.reads(Json.obj("props" -> JsNull)).mustEqual(JsSuccess(Optional(None)))
formatter.reads(Json.obj("props" -> Some("foo"))).mustEqual(JsSuccess(Optional(Some("foo"))))
}
"format value classes" in {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"format value classes" in {
"format value classes" in {

implicit val userIdFmt: Format[UserId] = Json.format[UserId]
val userId = UserId(12345)
val serialized = Json.stringify(Json.toJson(userId))
serialized.mustEqual("""{"id":12345}""")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
serialized.mustEqual("""{"id":12345}""")
serialized.mustEqual("""{"id":12345}""")

Json.fromJson[UserId](Json.parse(serialized)).mustEqual(JsSuccess(userId))
}
"format value classes with value format" in {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"format value classes with value format" in {
"format value classes with value format" in {

implicit val userIdFmt: Format[UserId] = Json.valueFormat[UserId]
val userId = UserId(12345)
val serialized = Json.stringify(Json.toJson(userId))
serialized.mustEqual("""12345""")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
serialized.mustEqual("""12345""")
serialized.mustEqual("""12345""")

Json.fromJson[UserId](Json.parse(serialized)).mustEqual(JsSuccess(userId))
}
}
}