Skip to content

Add DeriveConfig support for Map with non-String keys via ConfigKeyDecoder#1658

Open
loathwine wants to merge 4 commits intozio:series/4.xfrom
loathwine:support-map-with-stringly-keys
Open

Add DeriveConfig support for Map with non-String keys via ConfigKeyDecoder#1658
loathwine wants to merge 4 commits intozio:series/4.xfrom
loathwine:support-map-with-stringly-keys

Conversation

@loathwine
Copy link
Copy Markdown

Summary

Adds ConfigKeyDecoder[K] typeclass to support Map[K, V] where K is not String, fixing #1381.

Previously, DeriveConfig only supported Map[String, V] via Config.table. This adds a ConfigKeyDecoder trait that decodes map keys from their string representation, with built-in instances for String, UUID, Int, and Long.

This is particularly useful for libraries like neotype where wrapper types are commonly used as map keys — see kitlangton/neotype#413 for a concrete use case.

Usage

// Built-in key types work out of the box
case class MyConfig(entries: Map[UUID, String])
val config = deriveConfig[MyConfig]

// Custom key types need a ConfigKeyDecoder instance
case class EntryId(value: String)
given ConfigKeyDecoder[EntryId] = (key: String) => Right(EntryId(key))

Changes

  • New ConfigKeyDecoder trait with built-in instances for String, UUID, Int, Long
  • Replaced Map[String, V]-only mapDesc with generalized Map[K, V] version using ConfigKeyDecoder[K]
  • Backwards compatible — Map[String, V] continues to work as before
  • Supports Scala 2.12, 2.13, and 3

Test plan

  • Map[String, Int] — backwards compatibility
  • Map[UUID, String] — UUID keys parsed from config
  • Map[Int, String] — Int keys parsed from config
  • Invalid key — error propagation
  • Case class containing Map[UUID, CaseClass] — automatic derivation

@loathwine loathwine requested a review from a team as a code owner February 10, 2026 21:10
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 10, 2026

CLA assistant check
All committers have signed the CLA.

* Introduced ConfigKeyDecoder trait to enable decoding map keys from strings
* Added built-in decoders for String, UUID, Int, and Long
* Updated DeriveConfig.implicitMapDesc to support Map[K, V] with custom key types
* Implemented for both Scala 2.12-2.13 and Scala 3 (dotty)
* Added comprehensive test suite covering String, UUID, Int keys and nested case classes
@loathwine loathwine force-pushed the support-map-with-stringly-keys branch from f767770 to af24c50 Compare February 10, 2026 21:15
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