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

org.http4k.connect.mattermost.model.KotshiAttachmentJsonAdapter.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.JsonAdapter
import com.squareup.moshi.JsonDataException
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.StringBuilder
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.core.Uri
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 KotshiAttachmentJsonAdapter(
  moshi: Moshi,
) : NamedJsonAdapter("KotshiJsonAdapter(Attachment)") {
  private val authorLinkAdapter: JsonAdapter = moshi.adapter(
      Uri::class.javaObjectType,
      setOf(),
      "authorLink"
  )

  private val authorIconAdapter: JsonAdapter = moshi.adapter(
      Uri::class.javaObjectType,
      setOf(),
      "authorIcon"
  )

  private val titleLinkAdapter: JsonAdapter = moshi.adapter(
      Uri::class.javaObjectType,
      setOf(),
      "titleLink"
  )

  private val fieldsAdapter: JsonAdapter?> = moshi.adapter(
      newParameterizedType(List::class.javaObjectType, AttachmentField::class.javaObjectType),
      setOf(),
      "fields"
  )

  private val imageUrlAdapter: JsonAdapter = moshi.adapter(
      Uri::class.javaObjectType,
      setOf(),
      "imageUrl"
  )

  private val thumbUrlAdapter: JsonAdapter = moshi.adapter(
      Uri::class.javaObjectType,
      setOf(),
      "thumbUrl"
  )

  private val actionsAdapter: JsonAdapter?> = moshi.adapter(
      newParameterizedType(List::class.javaObjectType, PostAction::class.javaObjectType),
      setOf(),
      "actions"
  )

  private val options: JsonReader.Options = JsonReader.Options.of(
      "fallback",
      "color",
      "pretext",
      "text",
      "author_name",
      "author_link",
      "author_icon",
      "title",
      "title_link",
      "fields",
      "image_url",
      "thumb_url",
      "footer",
      "footer_icon",
      "actions"
  )

  @Volatile
  private var defaultConstructor: Constructor? = null

  @Throws(IOException::class)
  override fun toJson(writer: JsonWriter, `value`: Attachment?) {
    if (`value` == null) {
      writer.nullValue()
      return
    }
    writer
      .beginObject()
      .name("fallback").value(`value`.fallback)
      .name("color").value(`value`.color)
      .name("pretext").value(`value`.pretext)
      .name("text").value(`value`.text)
      .name("author_name").value(`value`.authorName)
      .name("author_link").apply {
        authorLinkAdapter.toJson(this, `value`.authorLink)
      }
      .name("author_icon").apply {
        authorIconAdapter.toJson(this, `value`.authorIcon)
      }
      .name("title").value(`value`.title)
      .name("title_link").apply {
        titleLinkAdapter.toJson(this, `value`.titleLink)
      }
      .name("fields").apply {
        fieldsAdapter.toJson(this, `value`.fields)
      }
      .name("image_url").apply {
        imageUrlAdapter.toJson(this, `value`.imageUrl)
      }
      .name("thumb_url").apply {
        thumbUrlAdapter.toJson(this, `value`.thumbUrl)
      }
      .name("footer").value(`value`.footer)
      .name("footer_icon").value(`value`.footerIcon)
      .name("actions").apply {
        actionsAdapter.toJson(this, `value`.actions)
      }
      .endObject()
  }

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

    var mask = -1
    var fallback: String? = null
    var color: String? = null
    var pretext: String? = null
    var text: String? = null
    var authorName: String? = null
    var authorLink: Uri? = null
    var authorIcon: Uri? = null
    var title: String? = null
    var titleLink: Uri? = null
    var fields: List? = null
    var imageUrl: Uri? = null
    var thumbUrl: Uri? = null
    var footer: String? = null
    var footerIcon: String? = null
    var actions: List? = null

    reader.beginObject()
    while (reader.hasNext()) {
      when (reader.selectName(options)) {
        0 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            fallback = reader.nextString()
          }
        }
        1 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            color = reader.nextString()
          }
          // $mask = $mask and (1 shl 1).inv()
          mask = mask and 0xfffffffd.toInt()
        }
        2 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            pretext = reader.nextString()
          }
          // $mask = $mask and (1 shl 2).inv()
          mask = mask and 0xfffffffb.toInt()
        }
        3 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            text = reader.nextString()
          }
        }
        4 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            authorName = reader.nextString()
          }
          // $mask = $mask and (1 shl 4).inv()
          mask = mask and 0xffffffef.toInt()
        }
        5 -> {
          authorLink = authorLinkAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 5).inv()
          mask = mask and 0xffffffdf.toInt()
        }
        6 -> {
          authorIcon = authorIconAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 6).inv()
          mask = mask and 0xffffffbf.toInt()
        }
        7 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            title = reader.nextString()
          }
          // $mask = $mask and (1 shl 7).inv()
          mask = mask and 0xffffff7f.toInt()
        }
        8 -> {
          titleLink = titleLinkAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 8).inv()
          mask = mask and 0xfffffeff.toInt()
        }
        9 -> {
          fields = fieldsAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 9).inv()
          mask = mask and 0xfffffdff.toInt()
        }
        10 -> {
          imageUrl = imageUrlAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 10).inv()
          mask = mask and 0xfffffbff.toInt()
        }
        11 -> {
          thumbUrl = thumbUrlAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 11).inv()
          mask = mask and 0xfffff7ff.toInt()
        }
        12 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            footer = reader.nextString()
          }
          // $mask = $mask and (1 shl 12).inv()
          mask = mask and 0xffffefff.toInt()
        }
        13 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            footerIcon = reader.nextString()
          }
          // $mask = $mask and (1 shl 13).inv()
          mask = mask and 0xffffdfff.toInt()
        }
        14 -> {
          actions = actionsAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 14).inv()
          mask = mask and 0xffffbfff.toInt()
        }
        -1 -> {
          reader.skipName()
          reader.skipValue()
        }
      }
    }
    reader.endObject()

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

    return if (mask == 0xffff8009.toInt()) {
      Attachment(
          fallback = fallback!!,
          color = color,
          pretext = pretext,
          text = text!!,
          authorName = authorName,
          authorLink = authorLink,
          authorIcon = authorIcon,
          title = title,
          titleLink = titleLink,
          fields = fields,
          imageUrl = imageUrl,
          thumbUrl = thumbUrl,
          footer = footer,
          footerIcon = footerIcon,
          actions = actions
      )
    } else {
      // Reflectively invoke the synthetic defaults constructor
      @Suppress("UNCHECKED_CAST")
      val localConstructor: Constructor = this.defaultConstructor ?:
          Attachment::class.java.getDeclaredConstructor(
            String::class.java,
            String::class.java,
            String::class.java,
            String::class.java,
            String::class.java,
            Uri::class.java,
            Uri::class.java,
            String::class.java,
            Uri::class.java,
            List::class.java,
            Uri::class.java,
            Uri::class.java,
            String::class.java,
            String::class.java,
            List::class.java,
            Int::class.javaPrimitiveType,
            DefaultConstructorMarker::class.java
          ).also { this.defaultConstructor = it }
      localConstructor.newInstance(
          fallback,
          color,
          pretext,
          text,
          authorName,
          authorLink,
          authorIcon,
          title,
          titleLink,
          fields,
          imageUrl,
          thumbUrl,
          footer,
          footerIcon,
          actions,
          mask,
          /* DefaultConstructorMarker */ null
      )
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy