Skip to content

Draft: Close #955 - Map key constraint - #1413

Draft
cchantep wants to merge 2 commits into
playframework:mainfrom
cchantep:fix/955_key_constraint
Draft

Draft: Close #955 - Map key constraint#1413
cchantep wants to merge 2 commits into
playframework:mainfrom
cchantep:fix/955_key_constraint

Conversation

@cchantep

Copy link
Copy Markdown
Member

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 #955

Purpose

Fix implicit resolution of KeyReads / KeyWrites for types represented as JSON strings.

readableKeyReads currently derives a KeyReads[T] from any Reads[T]. This is too broad: types such as tuples have a Reads, but are not represented as JSON strings and therefore cannot be used as JSON object keys through this mechanism.

This PR introduces Format.Representation[T, R] as explicit evidence that a type has a given JSON representation, and uses it to constrain the string-based KeyReads / KeyWrites derivation.

The existing readableKeyReads is kept for backward compatibility but deprecated.

Background Context

A Reads[T] does not imply that T can be read from a JsString. For example, Reads[(Int, Int)] exists even though (Int, Int) is not a string representation (unlike for example URI which is represented as JSON string).

The new Representation[T, JsString] makes this distinction explicit and prevents KeyReads / KeyWrites from being derived for types that are not string-represented.

Representations for types whose JSON representation depends on the Writes / Reads (e.g. temporal types, duration, ...) in scope are provided separately through Format.Representation.Implicits, so they are opt-in rather than unconditional.

@cchantep cchantep changed the title Close #955 - Map key constraint Draft: Close #955 - Map key constraint Aug 31, 2026
@cchantep
cchantep force-pushed the fix/955_key_constraint branch from 8a951b0 to 9f03b35 Compare August 31, 2026 21:40
@cchantep
cchantep force-pushed the fix/955_key_constraint branch from 9f03b35 to 642320b Compare August 31, 2026 21:45
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.

LowPriorityKeyReads.readableKeyReads should not exist

1 participant