-
-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added tests to format value classes #1041
base: main
Are you sure you want to change the base?
Added tests to format value classes #1041
Conversation
09730f7
to
627ffe2
Compare
@@ -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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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}""") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serialized.mustEqual("""{"id":12345}""") | |
serialized.mustEqual("""{"id":12345}""") |
serialized.mustEqual("""{"id":12345}""") | ||
Json.fromJson[UserId](Json.parse(serialized)).mustEqual(JsSuccess(userId)) | ||
} | ||
"format value classes with value format" in { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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""") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serialized.mustEqual("""12345""") | |
serialized.mustEqual("""12345""") |
Pull Request Checklist
Purpose
This PR demonstrates #1011. The Json.format[UserId] fails to compile with Scala 3: