Skip to content

Conversation

@DavidGregory084
Copy link

@DavidGregory084 DavidGregory084 commented Jun 18, 2025

Pull Request Checklist

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

Fixes

Fixes #1089.

Purpose

This PR adds support for Scala 3's Type Class Derivation when using Reads, Writes and Format.

For example:

case class Resident(name: String, age: Int, role: Option[String]) derives Reads

This is done by providing an inline def derived in the companion object of Reads, Writes and Format that simply forwards to the appropriate Json macro implementation.

Background Context

Using an inline def should ensure that derives Reads behaves the same way as adding a given declaration to the class's companion object:

object Resident {
  given Reads[Resident] = Json.reads[Resident]
}

This expansion is described in the documentation for type class derivation, especially the example for Point.

References

Please see the Reddit discussion linked in issue #1089.

@DavidGregory084 DavidGregory084 changed the title Add support for Scala 3 type class derivation of Format, Writes and Reads Add support for Scala 3 type class derivation of Format, Writes and Reads Jun 18, 2025
@DavidGregory084

This comment was marked as resolved.

@gaeljw
Copy link
Member

gaeljw commented Jan 7, 2026

That looks really great. Scala 3 users will be happy to get this :)

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.

[Feature] Support typeclass derivation (derives) from Scala 3

2 participants