Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*<br>
* For instance:
* <ul>
* <li>For a class "com.example.MyClass", only "MyClass" is used.</li>
* <li>For an inner class "com.example.MyClass$Inner", only "Inner" is used.</li>
* </ul>
* <b>Note:</b> This approach reduces verbosity but requires the simple names to be unique
* to avoid conflicts. If multiple classes share the same simple name, <b>the last declared one</b>
* 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 <i>deduced</i> based
* on the fields available. Deduction is limited to the <i>names</i> of fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down