Skip to content

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

Description

@salatmaster

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.0Issue planned for initial 3.0 releasemost-wantedTag to indicate that there is heavy user +1'ing action (5 or more)

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions