stringSerializer

@ExperimentalSince(version = KotoolsTypesVersion.V5_0_1)
fun EmailAddressRegex.Companion.stringSerializer(): KSerializer<EmailAddressRegex>

Returns an object responsible for serializing the EmailAddressRegex type as String.


Calling from Kotlin

Here's an example of Kotlin code that encodes and decodes the EmailAddressRegex type using the JavaScript Object Notation (JSON) format from kotlinx.serialization and this function:

val serializer: KSerializer<EmailAddressRegex> =
    EmailAddressRegex.stringSerializer()
val regex: EmailAddressRegex = EmailAddressRegex.default()
val encoded: String = Json.encodeToString(serializer, regex)
regex.toString()
    .replace(oldValue = "\\", newValue = "\\\\")
    .let { assertEquals("\"$it\"", encoded) }
val decoded: EmailAddressRegex =
    Json.decodeFromString(serializer, encoded)
assertEquals(regex, decoded)

@ExperimentalSince(version = KotoolsTypesVersion.V5_0_1)
fun EmailAddress.Companion.stringSerializer(): KSerializer<EmailAddress>

Returns an object responsible for serializing the EmailAddress type as String.


Calling from Kotlin

Here's an example of Kotlin code that encodes and decodes the EmailAddress type using the JavaScript Object Notation (JSON) format from kotlinx.serialization and this function:

val serializer: KSerializer<EmailAddress> =
    EmailAddress.stringSerializer()
val address: EmailAddress = EmailAddress.orThrow("contact@kotools.org")
val encoded: String = Json.encodeToString(serializer, address)
assertEquals("\"$address\"", encoded)
val decoded: EmailAddress = Json.decodeFromString(serializer, encoded)
assertEquals(address, decoded)

@ExperimentalSince(version = KotoolsTypesVersion.V5_0_1)
fun Zero.Companion.stringSerializer(): KSerializer<Zero>

Returns an object responsible for serializing the Zero type as String.


Calling from Kotlin

Here's an example of Kotlin code that encodes and decodes the Zero type using the JavaScript Object Notation (JSON) format from kotlinx.serialization and this function:

val serializer: KSerializer<Zero> = Zero.stringSerializer()
val zero = Zero()
val encoded: String = Json.encodeToString(serializer, zero)
assertEquals(expected = "\"$zero\"", encoded)
val decoded: Zero = Json.decodeFromString(serializer, encoded)
assertEquals(zero, decoded)