Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

levinson
Copy link

Pull Request Checklist

  • Have you read through the contributor guidelines?
  • Have you squashed your commits?
  • Have you added copyright headers to new files? N/A
  • Have you updated the documentation? N/A
  • Have you added tests for any changed functionality? N/A

Purpose

This PR demonstrates #1011. The Json.format[UserId] fails to compile with Scala 3:

[error] -- Error: JsonExtensionSpec.scala:755:58
[error] 755 |      implicit val userIdFmt: Format[UserId] = Json.format[UserId]
[error]     |                                               ^^^^^^^^^^^^^^^^^^^
[error]     |            Instance not found: 'ProductOf[play.api.libs.json.UserId]'

@levinson levinson force-pushed the value-class-scala3-compile-bug branch from 09730f7 to 627ffe2 Compare May 11, 2024 20:37
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}""")

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""")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.