Files
gulevsky c9caf87860 add code generation of json serializers
commit_hash:3ad603b95c6c6ead4feaa591da3fbe2e91751455
2024-09-25 12:55:58 +03:00

68 lines
1.9 KiB
Kotlin

// Generated code. Do not modify.
package com.yandex.div.reference
import android.graphics.Color
import android.net.Uri
import androidx.annotation.ColorInt
import com.yandex.div.data.*
import com.yandex.div.json.*
import com.yandex.div.json.expressions.Expression
import com.yandex.div.json.expressions.ExpressionsList
import com.yandex.div.json.schema.*
import org.json.JSONArray
import org.json.JSONObject
class EntityWithArray(
@JvmField val array: List<Entity>, // at least 1 elements
) : JSONSerializable, Hashable {
private var _hash: Int? = null
override fun hash(): Int {
_hash?.let {
return it
}
val hash =
this::class.hashCode() +
array.sumOf { it.hash() }
_hash = hash
return hash
}
fun equals(other: EntityWithArray?, resolver: ExpressionResolver, otherResolver: ExpressionResolver): Boolean {
other ?: return false
return array.compareWith(other.array) { a, b -> a.equals(b, resolver, otherResolver) }
}
fun copy(
array: List<Entity> = this.array,
) = EntityWithArray(
array = array,
)
override fun writeToJSON(): JSONObject {
val json = JSONObject()
json.write(key = "array", value = array)
json.write(key = "type", value = TYPE)
return json
}
companion object {
const val TYPE = "entity_with_array"
@JvmStatic
@JvmName("fromJson")
operator fun invoke(env: ParsingEnvironment, json: JSONObject): EntityWithArray {
val logger = env.logger
return EntityWithArray(
array = JsonParser.readList(json, "array", Entity.CREATOR, ARRAY_VALIDATOR, logger, env)
)
}
private val ARRAY_VALIDATOR = ListValidator<Entity> { it: List<*> -> it.size >= 1 }
val CREATOR = { env: ParsingEnvironment, it: JSONObject -> EntityWithArray(env, json = it) }
}
}