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

org.http4k.connect.mattermost.model.KotshiAttachmentFieldJsonAdapter.kt Maven / Gradle / Ivy

There is a newer version: 5.25.0.0
Show newest version
// Code generated by Kotshi. Do not edit.
package org.http4k.connect.mattermost.model

import com.squareup.moshi.JsonDataException
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import java.io.IOException
import java.lang.StringBuilder
import java.lang.reflect.Constructor
import kotlin.Boolean
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.jvm.Throws
import kotlin.jvm.Volatile
import kotlin.jvm.`internal`.DefaultConstructorMarker
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 KotshiAttachmentFieldJsonAdapter() :
    NamedJsonAdapter("KotshiJsonAdapter(AttachmentField)") {
  private val options: JsonReader.Options = JsonReader.Options.of(
      "title",
      "value",
      "short"
  )

  @Volatile
  private var defaultConstructor: Constructor? = null

  @Throws(IOException::class)
  override fun toJson(writer: JsonWriter, `value`: AttachmentField?) {
    if (`value` == null) {
      writer.nullValue()
      return
    }
    writer
      .beginObject()
      .name("title").value(`value`.title)
      .name("value").value(`value`.`value`)
      .name("short").value(`value`.short)
      .endObject()
  }

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

    var mask = -1
    var title: String? = null
    var value__: String? = null
    var short: Boolean? = null

    reader.beginObject()
    while (reader.hasNext()) {
      when (reader.selectName(options)) {
        0 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            title = reader.nextString()
          }
        }
        1 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            value__ = reader.nextString()
          }
        }
        2 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            short = reader.nextBoolean()
          }
          // $mask = $mask and (1 shl 2).inv()
          mask = mask and 0xfffffffb.toInt()
        }
        -1 -> {
          reader.skipName()
          reader.skipValue()
        }
      }
    }
    reader.endObject()

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

    return if (mask == 0xfffffffb.toInt()) {
      AttachmentField(
          title = title!!,
          `value` = value__!!,
          short = short
      )
    } else {
      // Reflectively invoke the synthetic defaults constructor
      @Suppress("UNCHECKED_CAST")
      val localConstructor: Constructor = this.defaultConstructor ?:
          AttachmentField::class.java.getDeclaredConstructor(
            String::class.java,
            String::class.java,
            Boolean::class.javaObjectType,
            Int::class.javaPrimitiveType,
            DefaultConstructorMarker::class.java
          ).also { this.defaultConstructor = it }
      localConstructor.newInstance(
          title,
          value__,
          short,
          mask,
          /* DefaultConstructorMarker */ null
      )
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy