Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails with recursion error if kotlinx.serialization is also applied #27

Closed
rickclephas opened this issue Dec 16, 2021 · 1 comment · Fixed by #28
Closed

Build fails with recursion error if kotlinx.serialization is also applied #27

rickclephas opened this issue Dec 16, 2021 · 1 comment · Fixed by #28
Assignees

Comments

@rickclephas
Copy link
Owner

When the kotlinx.serialization plugin is applied the build fails with a recursion error for the following class:

@Serializable
class Base64ByteArray(val value: ByteArray) {
    @Serializer(Base64ByteArray::class)
    companion object : KSerializer<Base64ByteArray> {
        override val descriptor = PrimitiveSerialDescriptor("Base64ByteArray", PrimitiveKind.STRING)
        override fun serialize(encoder: Encoder, obj: Base64ByteArray) = encoder.encodeString(obj.value.decodeToString())
        override fun deserialize(decoder: Decoder) = Base64ByteArray(decoder.decodeString().encodeToByteArray())
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other == null || this::class != other::class) return false
        other as Base64ByteArray
        return value.contentEquals(other.value)
    }

    override fun hashCode(): Int {
        return value.contentHashCode()
    }

    override fun toString(): String {
        return "Base64ByteArray(${value})"
    }
}

Also see #23 (comment).

@rickclephas
Copy link
Owner Author

@GrahamBorland explicitly specifying the return type of descriptor will "fix" the build:

override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Base64ByteArray", PrimitiveKind.STRING)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant