File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
main/java/com/fasterxml/jackson/annotation
test/java/com/fasterxml/jackson/annotation Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,23 @@ public enum Id {
119
119
*/
120
120
NAME ("@type" ),
121
121
122
+ /**
123
+ * Means that the simple name of the Java class, equivalent to the value returned by {@link Class#getSimpleName()},
124
+ * is used as the default type identifier, unless explicit name is specified by annotation {@link JsonTypeName}.
125
+ *<br>
126
+ * For instance:
127
+ * <ul>
128
+ * <li>For a class "com.example.MyClass", only "MyClass" is used.</li>
129
+ * <li>For an inner class "com.example.MyClass$Inner", only "Inner" is used.</li>
130
+ * </ul>
131
+ * <b>Note:</b> This approach reduces verbosity but requires the simple names to be unique
132
+ * to avoid conflicts. If multiple classes share the same simple name, <b>the last declared one</b>
133
+ * will be used. This approach should be used with careful consideration of your type hierarchy.
134
+ *
135
+ * @since 2.16
136
+ */
137
+ SIMPLE_NAME ("@type" ),
138
+
122
139
/**
123
140
* Means that no serialized typing-property is used. Types are <i>deduced</i> based
124
141
* on the fields available. Deduction is limited to the <i>names</i> of fields
Original file line number Diff line number Diff line change @@ -61,6 +61,8 @@ public void testMutators() throws Exception
61
61
assertSame (v , v .withIdType (JsonTypeInfo .Id .CLASS ));
62
62
JsonTypeInfo .Value v2 = v .withIdType (JsonTypeInfo .Id .MINIMAL_CLASS );
63
63
assertEquals (JsonTypeInfo .Id .MINIMAL_CLASS , v2 .getIdType ());
64
+ JsonTypeInfo .Value v3 = v .withIdType (JsonTypeInfo .Id .SIMPLE_NAME );
65
+ assertEquals (JsonTypeInfo .Id .SIMPLE_NAME , v3 .getIdType ());
64
66
65
67
assertEquals (JsonTypeInfo .As .PROPERTY , v .getInclusionType ());
66
68
assertSame (v , v .withInclusionType (JsonTypeInfo .As .PROPERTY ));
You can’t perform that action at this time.
0 commit comments