Skip to content

Commit

Permalink
recursion instead of while loop, selector annotations instead of Json…
Browse files Browse the repository at this point in the history
…Config and small improvements
  • Loading branch information
goshacodes committed Jul 22, 2024
1 parent af29911 commit 681ac6d
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 570 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,19 @@ session.asJson == json
```

## Sealed traits and enums
To derive **JsonReader** you **must** provide **JsonConfig** with discriminator.
To derive **JsonReader** you **must** provide a discriminator.
This can be done via **selector** annotation
Discriminator for **JsonWriter** is optional.

If you don't need readers/writers for subtypes, you can omit them,
they will be derived recursively for your trait/enum.

```scala 3
import tethys.selector

sealed trait UserAccount(val typ: String) derives JsonReader, JsonObjectWriter
sealed trait UserAccount(@selector val typ: String) derives JsonReader, JsonObjectWriter

object UserAccount:
inline given JsonConfig[UserAccount] =
JsonConfig[UserAccount].discriminateBy(_.typ)

case class Customer(
id: Long,
phone: String
Expand Down
10 changes: 0 additions & 10 deletions modules/core/src/main/scala-3/tethys/JsonConfig.scala

This file was deleted.

Loading

0 comments on commit 681ac6d

Please sign in to comment.