Skip to content

Add JsonTypeInfo.Id.SIMPLE_NAME which defaults type id to Class.getSimpleName() #4061

@ooraini

Description

@ooraini

Is your feature request related to a problem? Please describe.

Add JsonTypeInfo.Id.SIMPLE_NAME that would use Class::getSimpleName for type ids.

My use case is sealed hierarchies where there is single sealed super interface, it would result in cleaner type ids. My work around:

            // AnnotationIntrospector
            @Override
            public String findTypeName(AnnotatedClass ac) {
                if (Arrays.stream(ac.getAnnotated().getInterfaces()).filter(Class::isSealed).count() == 1) {
                    return ac.getAnnotated().getSimpleName();
                }

                return super.findTypeName(ac);
            }

Describe the solution you'd like

JsonTypeInfo.Id.SIMPLE_NAME

Usage example

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions