org.http4k.connect.mattermost.model.KotshiPostActionOptionJsonAdapter.kt Maven / Gradle / Ivy
// Code generated by Kotshi. Do not edit.
package org.http4k.connect.mattermost.model
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.Suppress
import kotlin.apply
import kotlin.collections.setOf
import kotlin.jvm.Throws
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 KotshiPostActionOptionJsonAdapter(
moshi: Moshi,
) : NamedJsonAdapter("KotshiJsonAdapter(PostActionOption)") {
private val textAdapter: JsonAdapter = moshi.adapter(
PostActionOptionText::class.javaObjectType,
setOf(),
"text"
)
private val valueAdapter: JsonAdapter = moshi.adapter(
PostActionOptionValue::class.javaObjectType,
setOf(),
"value"
)
private val options: JsonReader.Options = JsonReader.Options.of(
"text",
"value"
)
@Throws(IOException::class)
override fun toJson(writer: JsonWriter, `value`: PostActionOption?) {
if (`value` == null) {
writer.nullValue()
return
}
writer
.beginObject()
.name("text").apply {
textAdapter.toJson(this, `value`.text)
}
.name("value").apply {
valueAdapter.toJson(this, `value`.`value`)
}
.endObject()
}
@Throws(IOException::class)
override fun fromJson(reader: JsonReader): PostActionOption? {
if (reader.peek() == JsonReader.Token.NULL) return reader.nextNull()
var text: PostActionOptionText? = null
var value__: PostActionOptionValue? = null
reader.beginObject()
while (reader.hasNext()) {
when (reader.selectName(options)) {
0 -> {
text = textAdapter.fromJson(reader)
}
1 -> {
value__ = valueAdapter.fromJson(reader)
}
-1 -> {
reader.skipName()
reader.skipValue()
}
}
}
reader.endObject()
var errorBuilder: StringBuilder? = null
if (text == null) {
errorBuilder = errorBuilder.appendNullableError("text")
}
if (value__ == null) {
errorBuilder = errorBuilder.appendNullableError("value")
}
if (errorBuilder != null) {
errorBuilder.append(" (at path ").append(reader.path).append(')')
throw JsonDataException(errorBuilder.toString())
}
return PostActionOption(
text = text!!,
`value` = value__!!
)
}
}