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

Use default match case for discriminator map #60

Merged
merged 2 commits into from
Sep 12, 2024

Conversation

cristiborta
Copy link
Contributor

@cristiborta cristiborta commented Sep 12, 2024

We overlooked the generic case when mapping keys from discriminator.

implicit lazy val decoder: Decoder[KeyBaseDiscriminator] = new Decoder[KeyBaseDiscriminator] {
  override def apply(c: HCursor): Result[KeyBaseDiscriminator] = c.value.asObject.toRight(DecodingFailure("Expected object", c.history)).flatMap { obj =>
    obj match {
      case _ if obj.contains("prefix") =>
        KeyBasePrefixString.decoder.tryDecode(c).fold(_ => KeyBasePrefixInt.decoder.tryDecode(c), Right(_))
      case _ if obj.contains("wildcard") =>
        KeyBaseWildcard.decoder.tryDecode(c)
     //we also need a generic case
      case other =>
        Left(DecodingFailure(s"unknown discriminator: ${other.keys.headOption.getOrElse("unknown_value")}", c.history))
    }
  }
}

@cristiborta cristiborta merged commit 9a3d46b into main Sep 12, 2024
6 checks passed
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