All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.http4k.connect.azure.action.KotshiToolJsonAdapter.kt Maven / Gradle / Ivy

// Code generated by Kotshi. Do not edit.
package org.http4k.connect.azure.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.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 KotshiToolJsonAdapter(
  moshi: Moshi,
) : NamedJsonAdapter("KotshiJsonAdapter(Tool)") {
  private val functionAdapter: JsonAdapter = moshi.adapter(
      FunctionSpec::class.javaObjectType,
      setOf(),
      "function"
  )

  private val options: JsonReader.Options = JsonReader.Options.of("function")

  @Throws(IOException::class)
  override fun toJson(writer: JsonWriter, `value`: Tool?) {
    if (`value` == null) {
      writer.nullValue()
      return
    }
    writer
      .beginObject()
      .name("function").apply {
        functionAdapter.toJson(this, `value`.function)
      }
      .endObject()
  }

  @Throws(IOException::class)
  override fun fromJson(reader: JsonReader): Tool? {
    if (reader.peek() == JsonReader.Token.NULL) return reader.nextNull()

    var function: FunctionSpec? = null

    reader.beginObject()
    while (reader.hasNext()) {
      when (reader.selectName(options)) {
        0 -> {
          function = functionAdapter.fromJson(reader)
        }
        -1 -> {
          reader.skipName()
          reader.skipValue()
        }
      }
    }
    reader.endObject()

    var errorBuilder: StringBuilder? = null
    if (function == null) {
      errorBuilder = errorBuilder.appendNullableError("function")
    }
    if (errorBuilder != null) {
      errorBuilder.append(" (at path ").append(reader.path).append(')')
      throw JsonDataException(errorBuilder.toString())
    }

    return Tool(
        function = function!!
    )
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy