Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 type identifier.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as the DEFAULT type identifier (unless explicit name specified by annotation @JsonTypeName)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done thank you!

*<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 first one declared</b>
* will be used. This approach should be used with careful consideration of your type hierarchy.
*
* @since 2.16
*/
SIMPLE_NAME("@simpl"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: should be "@simple". But should we instead just use @type, same as with Id.NAME -- after all these need not be unique/distinct?
Maybe worth asking in the original discussion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: should be "@simple".

thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though we certain are not restricted to make unique identifiers, I am hesitant to introduc duplication at this point 🤔🤔. If we can come up with suitable name, it will make sense to keep default identifier unique.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth asking in the original discussion?

Yes, for sure. Collective knowledge! Willl write a question overthere


/**
* 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