Skip to content

[Docs] Improve documentation for Scala3 enum derivation with jsoniter-scala #5236

@akreit

Description

@akreit

I took me quite some time to figure out how to parse a json body with jsoniter-scala where one of the fields is a (Scala 3) enum.

This is what works:

enum ColorEnum:
  case Green extends ColorEnum
  case Pink extends ColorEnum

object ColorEnum:
  given JsonValueCodec[ContextSource] = JsonCodecMaker.make(
      CodecMakerConfig.withDiscriminatorFieldName(None)
    )

  given Schema.derivedEnumeration.defaultStringBased

The following issue gave the hint to add the additional config in the JsconCodecMaker: plokhotnyuk/jsoniter-scala#1268.

I would imagine that tapir users would appreciate a hint for this in the docs on tapir's Enumeration support.
Happy to open a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions