Skip to content

Commit

Permalink
🗑️ Deprecate KotoolsTypesSerializers.zero property (#690)
Browse files Browse the repository at this point in the history
It is now recommended to use the `ZeroAsByteSerializer` type instead.
  • Loading branch information
LVMVRQUXL committed Aug 27, 2024
1 parent c76c1fe commit 13dedf3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotools.types.experimental.ExperimentalKotoolsTypesApi
import kotools.types.internal.simpleNameOf
import org.kotools.types.EmailAddress
import org.kotools.types.Zero
import org.kotools.types.internal.DeprecatedAsErrorSince
import org.kotools.types.internal.ExperimentalSince
import org.kotools.types.internal.KotoolsTypesVersion
import org.kotools.types.internal.Warning
Expand Down Expand Up @@ -36,7 +37,8 @@ public object KotoolsTypesSerializers {
public val all: SerializersModule
get() = SerializersModule {
include(this@KotoolsTypesSerializers.emailAddress)
include(this@KotoolsTypesSerializers.zero)
val zeroSerializer = ZeroAsByteSerializer()
this.contextual(zeroSerializer)
}

/**
Expand All @@ -58,20 +60,18 @@ public object KotoolsTypesSerializers {
contextual(EmailAddressAsStringSerializer)
}

/**
* Returns the module for serializing the [Zero] type.
*
* <br>
* <details>
* <summary>
* <b>Calling from Kotlin</b>
* </summary>
*
* Here's an example of calling this property from Kotlin code:
*
* SAMPLE: [org.kotools.types.kotlinx.serialization.KotoolsTypesSerializersCommonSample.zero]
* </details>
*/
/** Returns the module for serializing the [Zero] type. */
@Deprecated(
"Use the 'ZeroAsByteSerializer' type instead.",
ReplaceWith(
"SerializersModule { contextual(ZeroAsByteSerializer()) }",
"kotlinx.serialization.modules.SerializersModule",
"kotlinx.serialization.modules.contextual",
"org.kotools.types.kotlinx.serialization.ZeroAsByteSerializer"
),
DeprecationLevel.ERROR
)
@DeprecatedAsErrorSince(KotoolsTypesVersion.Unreleased)
public val zero: SerializersModule
get() = SerializersModule { contextual(ZeroAsByteSerializer) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ internal class KotoolsTypesSerializersCommonSample {
assertEquals(expected = emailAddress, actual = decoded)
}

@Test
fun zero() {
val format = Json { serializersModule = KotoolsTypesSerializers.zero }
val zero = Zero()
val encoded: String = format.encodeToString(zero)
assertEquals(expected = "0", actual = encoded)
val decoded: Zero = format.decodeFromString(encoded)
assertEquals(expected = zero, actual = decoded)
}

@Test
fun toStringOverride() {
val actual =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import kotools.types.internal.simpleNameOf
import org.kotools.types.EmailAddress
import org.kotools.types.Zero
import org.kotools.types.kotlinx.serialization.internal.EmailAddressAsStringSerializer
import org.kotools.types.kotlinx.serialization.internal.ZeroAsByteSerializer
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertSame
Expand All @@ -29,13 +28,6 @@ class KotoolsTypesSerializersTest {
assertSame(EmailAddressAsStringSerializer, serializer)
}

@Test
fun zero_module_should_contain_serializer_for_Zero_type() {
val module: SerializersModule = KotoolsTypesSerializers.zero
val serializer: KSerializer<Zero> = module.serializer()
assertSame(ZeroAsByteSerializer, serializer)
}

@Test
fun toString_should_return_its_simple_name() {
val actual: String = KotoolsTypesSerializers.toString()
Expand Down

0 comments on commit 13dedf3

Please sign in to comment.