Skip to content
New issue

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

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

Already on GitHub? # to your account

Auto-detect Java 17 sealed classes without manually specifying them in @JsonSubTypes #3281

Open
slutmaker opened this issue Sep 19, 2021 · 1 comment

Comments

@slutmaker
Copy link

Since sealed classes were included in the java 17 release as a stable feature, I think jackson should support them and automatically detect possible subtypes without the @JsonSubTypes annotation.

Usage example

    @JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
    sealed interface UserEvent permits UserCreatedEvent, UserBlockedEvent {
        int getUserId();
    }

    @Value
    final class UserCreatedEvent implements UserEvent {
        LocalDateTime createdAt;
        int userId;
        //...
    }

    @Value
    final class UserBlockedEvent implements UserEvent {
        LocalDateTime blockedFrom;
        LocalDateTime blockedTo;
        int userId;
        //...
    }

Additional context
Similar issue for kotlin sealed classes:
FasterXML/jackson-module-kotlin#239

@slutmaker slutmaker added the to-evaluate Issue that has been received but not yet evaluated label Sep 19, 2021
@slutmaker slutmaker changed the title Auto-detect java 17 sealed classes without manually specifying them in @JsonSubTypes Auto-detect Java 17 sealed classes without manually specifying them in @JsonSubTypes Sep 19, 2021
@nlisker
Copy link

nlisker commented Sep 25, 2021

I've suggested this at FasterXML/jackson-future-ideas#61 a while back and it was already evaluated, if that helps.

@cowtowncoder cowtowncoder added 3.x Issues to be only tackled for Jackson 3.x, not 2.x and removed to-evaluate Issue that has been received but not yet evaluated labels Oct 15, 2021
@cowtowncoder cowtowncoder removed the 3.x Issues to be only tackled for Jackson 3.x, not 2.x label Dec 1, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants