Skip to content

Commit 2516beb

Browse files
committed
Add sample of @FirebaseClassDiscriminator usage
1 parent c82bf3c commit 2516beb

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,28 @@ data class Post(
106106

107107
This sdk will handle polymorphic serialization automatically if you have a sealed class and its children marked as `Serializable`. It will include a `type` property that will be used to discriminate which child class is the serialized.
108108

109-
You can change this `type` property by using the `@FirebaseClassDiscrminator` annotation in the parent sealed class.
109+
You can change this `type` property by using the `@FirebaseClassDiscrminator` annotation in the parent sealed class:
110+
111+
```kotlin
112+
@Serializable
113+
@FirebaseClassDiscriminator("class")
114+
sealed class Parent {
115+
@Serializable
116+
@SerialName("child")
117+
data class Child(
118+
val property: Boolean
119+
) : Parent
120+
}
121+
```
122+
123+
In combination with a `SerialName` specified for the child class, you have full control over the serialized data. In this case it will be:
124+
125+
```json
126+
{
127+
class: "child",
128+
property: true
129+
}
130+
```
110131

111132
<h3><a href="https://kotlinlang.org/docs/reference/functions.html#default-arguments">Default arguments</a></h3>
112133

0 commit comments

Comments
 (0)