You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/docs/src/main/mdoc/docs/12-Custom-Mappings.md
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -177,6 +177,25 @@ implicit val jsonMeta: Meta[Json] =
177
177
178
178
There are similar constructors for array types and other possibilities, but `other` is by far the most common in user code and we won't discuss the others here. See the Scaladoc for more information.
179
179
180
+
## Derivation for Scala 3 enums
181
+
182
+
You can derive `Get` and `Put` instances for Scala 3 enums using the `Get.deriveEnumString` or `Put.deriveEnumString`.
183
+
184
+
```scala
185
+
enumColor:
186
+
caseRed, Green, Blue
187
+
188
+
objectColor:
189
+
givenGet[Color] =Get.deriveEnumString[Color]
190
+
givenPut[Color] =Put.deriveEnumString[Color]
191
+
192
+
fr"SELECT 'Red'".query[Color].unique
193
+
```
194
+
195
+
As shown above,
196
+
197
+
- The instances need to be explicitly derived
198
+
- The string values converts from/to are the literal name of the enum cases
0 commit comments