Repository: svix/svix-webhooks (language: rust)

Issue:
Kotlin SDK error when deleting an endpoint
It looks like the Kotlin SDK has same endpoints that aren't working well because it tries to use Unit (I assume as a no-content?) which fails with the below error. Maybe we need a way to (de?)serialize Unit, or alternatively fix the generator not to use Unit at all.

## Code
 
```kotlin
fun main() {
    val svix = Svix("key")
    runBlocking {
        svix.endpoint.delete("appId", "endpointId") // <-- this throws the exception
    }
}
```

## Exception
```
Exception in thread "main" java.lang.IllegalArgumentException: Platform class kotlin.Unit requires explicit JsonAdapter to be registered
                at com.squareup.moshi.ClassJsonAdapter$1.create(ClassJsonAdapter.java:75)
                at com.squareup.moshi.Moshi.adapter(Moshi.java:145)
                at com.squareup.moshi.Moshi.adapter(Moshi.java:105)
                at com.squareup.moshi.Moshi.adapter(Moshi.java:79)
                at com.svix.kotlin.internal.apis.EndpointApi.v1EndpointDelete(EndpointApi.kt:1506)
 ```


Discussion / hints:
I'm still looking into this. Hope to have a resolution in place by end of day.

Fix patch:
diff --git a/kotlin/templates/jvm-common/infrastructure/Serializer.kt.mustache b/kotlin/templates/jvm-common/infrastructure/Serializer.kt.mustache
deleted file mode 100644
index 31b83578e..000000000
--- a/kotlin/templates/jvm-common/infrastructure/Serializer.kt.mustache
+++ /dev/null
@@ -1,116 +0,0 @@
-package {{packageName}}.infrastructure
-
-{{#moshi}}
-import com.squareup.moshi.Moshi
-{{^moshiCodeGen}}
-import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
-{{/moshiCodeGen}}
-{{/moshi}}
-{{#gson}}
-import com.google.gson.Gson
-import com.google.gson.GsonBuilder
-{{^threetenbp}}
-import java.time.LocalDate
-import java.time.LocalDateTime
-import java.time.OffsetDateTime
-{{/threetenbp}}
-{{#threetenbp}}
-import org.threeten.bp.LocalDate
-import org.threeten.bp.LocalDateTime
-import org.threeten.bp.OffsetDateTime
-{{/threetenbp}}
-import java.util.UUID
-{{/gson}}
-{{#jackson}}
-import com.fasterxml.jackson.databind.ObjectMapper
-import com.fasterxml.jackson.databind.SerializationFeature
-import com.fasterxml.jackson.annotation.JsonInclude
-import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
-{{/jackson}}
-import java.util.Date
-{{#kotlinx_serialization}}
-import java.math.BigDecimal
-import java.math.BigInteger
-{{^threetenbp}}
-import java.time.LocalDate
-import java.time.LocalDateTime
-import java.time.OffsetDateTime
-{{/threetenbp}}
-{{#threetenbp}}
-import org.threeten.bp.LocalDate
-import org.threeten.bp.LocalDateTime
-import org.threeten.bp.OffsetDateTime
-{{/threetenbp}}
-import java.util.UUID
-import kotlinx.serialization.json.Json
-import kotlinx.serialization.modules.SerializersModule
-import java.net.URI
-import java.net.URL
-import java.util.concurrent.atomic.AtomicBoolean
-import java.util.concurrent.atomic.AtomicInteger
-import java.util.concurrent.atomic.AtomicLong
-{{/kotlinx_serialization}}
-
-{{#nonPublicApi}}internal {{/nonPublicApi}}object Serializer {
-{{#moshi}}
-    @JvmStatic
-    val moshiBuilder: Moshi.Builder = Moshi.Builder()
-        .add(OffsetDateTimeAdapter())
-        .add(LocalDateTimeAdapter())
-        .add(LocalDateAdapter())
-        .add(UUIDAdapter())
-        .add(ByteArrayAdapter())
-        .add(URIAdapter())
-        {{^moshiCodeGen}}
-        .add(KotlinJsonAdapterFactory())
-        {{/moshiCodeGen}}
-        .add(BigDecimalAdapter())
-        .add(BigIntegerAdapter())
-
-    @JvmStatic
-    val moshi: Moshi by lazy {
-        moshiBuilder.build()
-    }
-{{/moshi}}
-{{#gson}}
-    @JvmStatic
-    val gsonBuilder: GsonBuilder = GsonBuilder()
-        .registerTypeAdapter(OffsetDateTime::class.java, OffsetDateTimeAdapter())
-        .registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeAdapter())
-        .registerTypeAdapter(LocalDate::class.java, LocalDateAdapter())
-        .registerTypeAdapter(ByteArray::class.java, ByteArrayAdapter())
-    
-    @JvmStatic
-    val gson: Gson by lazy {
-        gsonBuilder.create()
-    }
-{{/gson}}
-{{#jackson}}
-    @JvmStatic
-    val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper()
-        .findAndRegisterModules()
-        .setSerializationInclusion(JsonInclude.Include.NON_ABSENT)
-        .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
-{{/jackson}}
-{{#kotlinx_serialization}}
-    @JvmStatic
-    val kotlinSerializationAdapters = SerializersModule {
-        contextual(BigDecimal::class, BigDecimalAdapter)
-        contextual(BigInteger::class, BigIntegerAdapter)
-        contextual(Date::class, DateAdapter)
-        contextual(LocalDate::class, LocalDateAdapter)
-        contextual(LocalDateTime::class, LocalDateTimeAdapter)
-        contextual(OffsetDateTime::class, OffsetDateTimeAdapter)
-        contextual(UUID::class, UUIDAdapter)
-        contextual(AtomicInteger::class, AtomicIntegerAdapter)
-        contextual(AtomicLong::class, AtomicLongAdapter)
-        contextual(AtomicBoolean::class, AtomicBooleanAdapter)
-        contextual(URI::class, URIAdapter)
-        contextual(URL::class, URLAdapter)
-        contextual(StringBuilder::class, StringBuilderAdapter)
-    }
-
-    @JvmStatic
-    val jvmJson: Json by lazy { Json { serializersModule = kotlinSerializationAdapters } }
-{{/kotlinx_serialization}}
-}
diff --git a/kotlin/templates/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache b/kotlin/templates/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache
index dabdc7e97..9d4c3bc97 100644
--- a/kotlin/templates/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache
+++ b/kotlin/templates/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache
@@ -171,9 +171,16 @@ import kotlin.random.Random
             )
             {{/jvm-okhttp3}}
             {{#jvm-okhttp4}}
-            mediaType == JsonMediaType -> {{#moshi}}Serializer.moshi.adapter(T::class.java).toJson(content){{/moshi}}{{#gson}}Serializer.gson.toJson(content, T::class.java){{/gson}}{{#jackson}}Serializer.jacksonObjectMapper.writeValueAsString(content){{/jackson}}{{#kotlinx_serialization}}Serializer.jvmJson.encodeToString(content){{/kotlinx_serialization}}.toRequestBody(
-                mediaType.toMediaTypeOrNull()
-            )
+            mediaType == JsonMediaType -> {
+                // Don't call `toJson` on Unit type:
+                if (T::class.java == Unit::class.java) {
+                    ByteArray(0).toRequestBody()
+                } else {
+                    {{#moshi}}Serializer.moshi.adapter(T::class.java).toJson(content){{/moshi}}{{#gson}}Serializer.gson.toJson(content, T::class.java){{/gson}}{{#jackson}}Serializer.jacksonObjectMapper.writeValueAsString(content){{/jackson}}{{#kotlinx_serialization}}Serializer.jvmJson.encodeToString(content){{/kotlinx_serialization}}.toRequestBody(
+                        mediaType.toMediaTypeOrNull()
+                    )
+                }
+            }
             {{/jvm-okhttp4}}
             mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.")
             // TODO: this should be extended with other serializers


Test patch:
diff --git a/kotlin/lib/src/test/com/svix/kotlin/BasicTest.kt b/kotlin/lib/src/test/com/svix/kotlin/BasicTest.kt
index b763b8ee3..a514fb2d1 100644
--- a/kotlin/lib/src/test/com/svix/kotlin/BasicTest.kt
+++ b/kotlin/lib/src/test/com/svix/kotlin/BasicTest.kt
@@ -24,6 +24,7 @@ class BasicTest {
                     )
                 )
             )
+            svix.application.delete(applicationOut.id)
         }
     }