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

Allow @Serializer annotation on type parameter #1176

Closed
NiematojakTomasz opened this issue Oct 31, 2020 · 1 comment
Closed

Allow @Serializer annotation on type parameter #1176

NiematojakTomasz opened this issue Oct 31, 2020 · 1 comment
Labels

Comments

@NiematojakTomasz
Copy link

I was trying to workaround #614 by providing custom serializer to Nothing type. Seems it's currently impossible to provide custom serializer for type passed as generic type parameter.

Example:

@Serializable
sealed class CommandExecutionResult<out Result> {
    @Serializable
    class Success<out Result>(
        val result: Result
    ) : CommandExecutionResult<Result>() {
        override fun <T> map(function: (Result) -> T): Success<T> {
            return Success(function(result))
        }
    }

    @Serializable
    class Failure(
        val reason: FailureReason
    ) : CommandExecutionResult<@Serializer(NothingSerializer::class) Nothing>() {
        override fun <T> map(function: (Nothing) -> T): Failure = this
    }
}
@sandwwraith
Copy link
Member

Use @Serializable instead of @Serializer

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

No branches or pull requests

2 participants