diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java index e16c7414..47de0633 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java @@ -119,6 +119,23 @@ public enum Id { */ NAME("@type"), + /** + * Means that the simple name of the Java class, equivalent to the value returned by {@link Class#getSimpleName()}, + * is used as the default type identifier, unless explicit name is specified by annotation {@link JsonTypeName}. + *
+ * For instance: + * + * Note: This approach reduces verbosity but requires the simple names to be unique + * to avoid conflicts. If multiple classes share the same simple name, the last declared one + * will be used. This approach should be used with careful consideration of your type hierarchy. + * + * @since 2.16 + */ + SIMPLE_NAME("@type"), + /** * Means that no serialized typing-property is used. Types are deduced based * on the fields available. Deduction is limited to the names of fields diff --git a/src/test/java/com/fasterxml/jackson/annotation/JsonTypeInfoTest.java b/src/test/java/com/fasterxml/jackson/annotation/JsonTypeInfoTest.java index 82b76ccc..52e67848 100644 --- a/src/test/java/com/fasterxml/jackson/annotation/JsonTypeInfoTest.java +++ b/src/test/java/com/fasterxml/jackson/annotation/JsonTypeInfoTest.java @@ -61,6 +61,8 @@ public void testMutators() throws Exception assertSame(v, v.withIdType(JsonTypeInfo.Id.CLASS)); JsonTypeInfo.Value v2 = v.withIdType(JsonTypeInfo.Id.MINIMAL_CLASS); assertEquals(JsonTypeInfo.Id.MINIMAL_CLASS, v2.getIdType()); + JsonTypeInfo.Value v3 = v.withIdType(JsonTypeInfo.Id.SIMPLE_NAME); + assertEquals(JsonTypeInfo.Id.SIMPLE_NAME, v3.getIdType()); assertEquals(JsonTypeInfo.As.PROPERTY, v.getInclusionType()); assertSame(v, v.withInclusionType(JsonTypeInfo.As.PROPERTY));