
Some Scottish guy. Knows a bunch of stuff about computers. Sometimes applies this knowledge at @Stripe. Award-winning baker of shortbread. 🥉
- Tweets3.4K
- Following438
- Followers406
- Likes2.4K

ALT Screenshot of my Kotlin JSON deserialisation interface, which I use to deserialise webhook payloads into concrete data class instances. But this relies on `collectionId` being defined… ``` @Serializable // Use the Webflow collection ID on each item to automatically deserialise to a subclass @JsonClassDiscriminator("collectionId") sealed interface WebflowCmsItem { val id: String val collectionId: String val fieldData: WebflowCmsItemData } ```

ALT Screenshot of Kotlin code: ``` import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json @Serializable data class Person( val name: String, // Not serialised by default, unless `false`! val isCool: Boolean = true, ) fun main() { // Prints { "name": "You" } Json .encodeToString(Person("You")) .also { println(it) } // Prints { "name": "You", "isCool": true } Json { encodeDefaults = true } .encodeToString(Person("You")) .also { println(it) } } ```



















