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

Enum support for sealed interfaces #536

Closed
georgi-mirchev opened this issue Jan 11, 2024 · 3 comments
Closed

Enum support for sealed interfaces #536

georgi-mirchev opened this issue Jan 11, 2024 · 3 comments

Comments

@georgi-mirchev
Copy link

We cannot get Moshi sealed to work correctly with enums that implement a sealed interface. We have the following example:

@JsonClass(generateAdapter = true, generator = "sealed:outcome")
sealed interface Outcome {

    @TypeLabel("Complete")
    enum class Complete : Outcome {
        AUTHORISED,
        DECLINED,
    }

 @TypeLabel("Error")
    enum class Error : Outcome {
        USER_FAILURE,
        SYSTEM_FAILURE,
    }

Does it support such cases?

@ZacSweers
Copy link
Owner

Enums as sealed subtypes isn't a case I'd considered. PR is welcome though!

@ZacSweers
Copy link
Owner

I don't think it would work the way you've described in your sample though. They'd be more akin to a nested sealed subtype and would work functionally the same as this

sealed class Error : Outcome {
  @TypeLabel(...)
  object USER_FAILURE : Error()
  @TypeLabel(...)
  object SYSTEM_FAILURE : Error()
}

@ZacSweers
Copy link
Owner

I'm going to close this as wontfix, the example you've put forward doesn't actually make much practical sense as there's no way to decide which enum member to use in your example. Feel free to revisit if you have an idea.

@ZacSweers ZacSweers closed this as not planned Won't fix, can't repro, duplicate, stale May 28, 2024
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

No branches or pull requests

2 participants