Skip to content

Commit c6b2d86

Browse files
committed
improve readme
1 parent 561685f commit c6b2d86

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,23 @@ Registered user:
6262
}
6363
```
6464

65-
Let's say we want to decode users into the following data structure:
65+
Let's say we want to decode guests and registered users into the following data structure:
6666

6767
```kotlin
6868
sealed interface User {
69-
data class Guest(val displayName: String) : User
70-
data class Registered(val id: Int, val alias: String, val email: String, val phone: String?) : User
69+
data class Guest(
70+
val displayName: String
71+
) : User
72+
data class Registered(
73+
val id: Int,
74+
val alias: String,
75+
val email: String,
76+
val phone: String?
77+
) : User
7178
}
7279
```
7380

74-
One way to define a decoder for `User` objects would be like this:
81+
First we need to define a `Decoder` for `User` objects like this:
7582

7683
```kotlin
7784
val userDecoder: Decoder<User> =
@@ -95,7 +102,7 @@ val userDecoder: Decoder<User> =
95102
}
96103
```
97104

98-
This decoder can now be used to parse and decode the users using the `decodeJson` function:
105+
We can now use `userDecoder` to parse and decode the JSON data using the `decodeJson` function:
99106

100107
```kotlin
101108
val guest = decodeJson(guestJson, userDecoder)

0 commit comments

Comments
 (0)