Skip to content
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

Case Class AnyVal Not Working with Json.reads/Json.writes #1011

Open
cheeseng opened this issue Apr 18, 2024 · 2 comments
Open

Case Class AnyVal Not Working with Json.reads/Json.writes #1011

cheeseng opened this issue Apr 18, 2024 · 2 comments

Comments

@cheeseng
Copy link
Member

cheeseng commented Apr 18, 2024

Are you looking for help?

This is an issue tracker, used to manage and track the development of Play JSON. It is not a support system and so it is not a place to ask questions or get help. If you're not sure if you have found a bug, the best place to start is with either the Play Discussion Forum or Stack Overflow.

If you want to discuss a feature request, the same tools are available.

Play JSON Version (2.5.x / etc)

3.0.2

API (Scala / Java / Neither / Both)

Scala

Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)

22.04.1-Ubuntu

JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)

openjdk version "17.0.9" 2023-10-17
OpenJDK Runtime Environment GraalVM CE 17.0.9+9.1 (build 17.0.9+9-jvmci-23.0-b22)
OpenJDK 64-Bit Server VM GraalVM CE 17.0.9+9.1 (build 17.0.9+9-jvmci-23.0-b22, mixed mode, sharing)

Library Dependencies

None.

Expected Behavior

Please describe the expected behavior of the issue, starting from the first action.

The following should compile (works under Scala 2.13):

case class UserId(id:Long) extends AnyVal

object UserId {
  implicit val reads: Reads[UserId] = Json.reads[UserId]
  implicit val writes: Writes[UserId] = Json.writes[UserId]
}

Actual Behavior

It fails to compile under Scala 3.3.3:

Instance not found: 'ProductOf[UserId]'

Reproducible Test Case

Example included in the ticket.

@xuwei-k
Copy link
Contributor

xuwei-k commented Jun 4, 2024

@cchantep
Copy link
Member

Class with AnyVal is a rather a Value class than a Case class (and in fact I would not recommended make it a case class).
There are dedicated macros for Value classes.

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

No branches or pull requests

3 participants