Skip to content

Commit

Permalink
extend docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ThijsBroersen committed Apr 29, 2024
1 parent 907420d commit 726b57f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/decoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ object Fruit {

Almost all of the standard library data types are supported as fields on the case class, and it is easy to add support if one is missing.

### Sealed families and enums for Scala 3
Sealed families where all members are only objects, or a Scala 3 enum with all cases parameterless are interpreted as enumerations and will encode 1:1 with their value-names.
```scala
enum Foo derives JsonDecoder:
case Bar
case Baz
case Qux
```
or
```scala
sealed trait Foo derives JsonDecoder
object Foo:
case object Bar extends Foo
case object Baz extends Foo
case object Qux extends Foo
```

## Manual instances

Sometimes it is easier to reuse an existing `JsonDecoder` rather than generate a new one. This can be accomplished using convenience methods on the `JsonDecoder` typeclass to *derive* new decoders
Expand Down
17 changes: 17 additions & 0 deletions docs/encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ apple.toJson

Almost all of the standard library data types are supported as fields on the case class, and it is easy to add support if one is missing.

### Sealed families and enums for Scala 3
Sealed families where all members are only objects, or a Scala 3 enum with all cases parameterless are interpreted as enumerations and will encode 1:1 with their value-names.
```scala
enum Foo derives JsonEncoder:
case Bar
case Baz
case Qux
```
or
```scala
sealed trait Foo derives JsonEncoder
object Foo:
case object Bar extends Foo
case object Baz extends Foo
case object Qux extends Foo
```

## Manual instances

Sometimes it is easier to reuse an existing `JsonEncoder` rather than generate a new one. This can be accomplished using convenience methods on the `JsonEncoder` typeclass to *derive* new decoders:
Expand Down

0 comments on commit 726b57f

Please sign in to comment.