org.http4k.connect.openai.action.KotshiMessageJsonAdapter.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.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types.newParameterizedType
import java.io.IOException
import java.lang.reflect.Constructor
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.apply
import kotlin.collections.List
import kotlin.collections.setOf
import kotlin.jvm.Throws
import kotlin.jvm.Volatile
import kotlin.jvm.`internal`.DefaultConstructorMarker
import org.http4k.connect.model.Role
import org.http4k.connect.openai.User
import se.ansman.kotshi.InternalKotshiApi
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 KotshiMessageJsonAdapter(
moshi: Moshi,
) : NamedJsonAdapter("KotshiJsonAdapter(Message)") {
private val roleAdapter: JsonAdapter = moshi.adapter(
Role::class.javaObjectType,
setOf(),
"role"
)
private val contentAdapter: JsonAdapter?> = moshi.adapter(
newParameterizedType(List::class.javaObjectType, MessageContent::class.javaObjectType),
setOf(),
"content"
)
private val nameAdapter: JsonAdapter = moshi.adapter(
User::class.javaObjectType,
setOf(),
"name"
)
private val tool_callsAdapter: JsonAdapter?> = moshi.adapter(
newParameterizedType(List::class.javaObjectType, ToolCall::class.javaObjectType),
setOf(),
"tool_calls"
)
private val options: JsonReader.Options = JsonReader.Options.of(
"role",
"content",
"name",
"refusal",
"tool_calls"
)
@Volatile
private var defaultConstructor: Constructor? = null
@Throws(IOException::class)
override fun toJson(writer: JsonWriter, `value`: Message?) {
if (`value` == null) {
writer.nullValue()
return
}
writer
.beginObject()
.name("role").apply {
roleAdapter.toJson(this, `value`.role)
}
.name("content").apply {
contentAdapter.toJson(this, `value`.content)
}
.name("name").apply {
nameAdapter.toJson(this, `value`.name)
}
.name("refusal").value(`value`.refusal)
.name("tool_calls").apply {
tool_callsAdapter.toJson(this, `value`.tool_calls)
}
.endObject()
}
@Throws(IOException::class)
override fun fromJson(reader: JsonReader): Message? {
if (reader.peek() == JsonReader.Token.NULL) return reader.nextNull()
var mask = -1
var role: Role? = null
var content: List? = null
var name: User? = null
var refusal: String? = null
var tool_calls: List? = null
reader.beginObject()
while (reader.hasNext()) {
when (reader.selectName(options)) {
0 -> {
role = roleAdapter.fromJson(reader)
}
1 -> {
content = contentAdapter.fromJson(reader)
// $mask = $mask and (1 shl 1).inv()
mask = mask and 0xfffffffd.toInt()
}
2 -> {
name = nameAdapter.fromJson(reader)
// $mask = $mask and (1 shl 2).inv()
mask = mask and 0xfffffffb.toInt()
}
3 -> {
if (reader.peek() == JsonReader.Token.NULL) {
reader.skipValue()
} else {
refusal = reader.nextString()
}
// $mask = $mask and (1 shl 3).inv()
mask = mask and 0xfffffff7.toInt()
}
4 -> {
tool_calls = tool_callsAdapter.fromJson(reader)
// $mask = $mask and (1 shl 4).inv()
mask = mask and 0xffffffef.toInt()
}
-1 -> {
reader.skipName()
reader.skipValue()
}
}
}
reader.endObject()
return if (mask == 0xffffffe1.toInt()) {
Message(
role = role,
content = content,
name = name,
refusal = refusal,
tool_calls = tool_calls
)
} else {
// Reflectively invoke the synthetic defaults constructor
@Suppress("UNCHECKED_CAST")
val localConstructor: Constructor =
this.defaultConstructor ?: Message::class.java.getDeclaredConstructor(
Role::class.java,
List::class.java,
User::class.java,
String::class.java,
List::class.java,
Int::class.javaPrimitiveType,
DefaultConstructorMarker::class.java
).also { this.defaultConstructor = it }
localConstructor.newInstance(
role,
content,
name,
refusal,
tool_calls,
mask,
/* DefaultConstructorMarker */ null
)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy