AnyInt
@Serializable(with = AnyIntSerializer::class)
@Since(version = KotoolsTypesVersion.V4_0_0)
Represents an integer number of type Int.
Serialization and deserialization
The serialization and deserialization processes of this type behave like for the Int type.
Here's an example of Kotlin code that encodes and decodes this type using the JavaScript Object Notation (JSON) format from kotlinx.serialization:
val number: AnyInt = 123.toNonZeroInt()
.getOrThrow()
val encoded: String = Json.encodeToString(number)
println(encoded) // 123
val decoded: AnyInt = Json.decodeFromString(encoded)
println(decoded == number) // true
Content copied to clipboard