org.http4k.connect.openai.action.KotshiChoiceJsonAdapter.kt Maven / Gradle / Ivy
// Code generated by Kotshi. Do not edit.
package org.http4k.connect.openai.action
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonDataException
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import java.io.IOException
import java.lang.StringBuilder
import kotlin.Boolean
import kotlin.Int
import kotlin.Suppress
import kotlin.apply
import kotlin.collections.setOf
import kotlin.jvm.Throws
import org.http4k.connect.model.FinishReason
import se.ansman.kotshi.InternalKotshiApi
import se.ansman.kotshi.KotshiUtils.appendNullableError
import se.ansman.kotshi.NamedJsonAdapter
@InternalKotshiApi
@Suppress(
"DEPRECATION",
"unused",
"ClassName",
"REDUNDANT_PROJECTION",
"RedundantExplicitType",
"LocalVariableName",
"RedundantVisibilityModifier",
"PLATFORM_CLASS_MAPPED_TO_KOTLIN",
"IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION",
"EXPERIMENTAL_API_USAGE",
"OPT_IN_USAGE",
)
internal class KotshiChoiceJsonAdapter(
moshi: Moshi,
) : NamedJsonAdapter("KotshiJsonAdapter(Choice)") {
private val msgAdapter: JsonAdapter = moshi.adapter(
ChoiceDetail::class.javaObjectType,
setOf(),
"msg"
)
private val deltaAdapter: JsonAdapter = moshi.adapter(
ChoiceDetail::class.javaObjectType,
setOf(),
"delta"
)
private val finish_reasonAdapter: JsonAdapter = moshi.adapter(
FinishReason::class.javaObjectType,
setOf(),
"finish_reason"
)
private val options: JsonReader.Options = JsonReader.Options.of(
"index",
"message",
"delta",
"finish_reason"
)
@Throws(IOException::class)
override fun toJson(writer: JsonWriter, `value`: Choice?) {
if (`value` == null) {
writer.nullValue()
return
}
writer
.beginObject()
.name("index").value(`value`.index)
.name("message").apply {
msgAdapter.toJson(this, `value`.msg)
}
.name("delta").apply {
deltaAdapter.toJson(this, `value`.delta)
}
.name("finish_reason").apply {
finish_reasonAdapter.toJson(this, `value`.finish_reason)
}
.endObject()
}
@Throws(IOException::class)
override fun fromJson(reader: JsonReader): Choice? {
if (reader.peek() == JsonReader.Token.NULL) return reader.nextNull()
var index: Int = 0
var indexIsSet: Boolean = false
var msg: ChoiceDetail? = null
var delta: ChoiceDetail? = null
var finish_reason: FinishReason? = null
reader.beginObject()
while (reader.hasNext()) {
when (reader.selectName(options)) {
0 -> {
if (reader.peek() == JsonReader.Token.NULL) {
reader.skipValue()
} else {
index = reader.nextInt()
indexIsSet = true
}
}
1 -> {
msg = msgAdapter.fromJson(reader)
}
2 -> {
delta = deltaAdapter.fromJson(reader)
}
3 -> {
finish_reason = finish_reasonAdapter.fromJson(reader)
}
-1 -> {
reader.skipName()
reader.skipValue()
}
}
}
reader.endObject()
var errorBuilder: StringBuilder? = null
if (!indexIsSet) {
errorBuilder = errorBuilder.appendNullableError("index")
}
if (errorBuilder != null) {
errorBuilder.append(" (at path ").append(reader.path).append(')')
throw JsonDataException(errorBuilder.toString())
}
return Choice(
index = index,
msg = msg,
delta = delta,
finish_reason = finish_reason
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy