Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new OptBoolean valued property in @JsonTypeInfo to allow per-type configuration of strict type id handling #223

Merged
merged 2 commits into from
May 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public enum As {
*
* @since 2.5
public boolean skipWritingDefault() default false;
/*
*/
Copy link
Member Author

Choose a reason for hiding this comment

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

Above JavaDoc was not closed properly. Maybe we can take this further to remove the comment from year 2014, since it is version-controlled?

// 19-Dec-2014, tatu: Was hoping to implement for 2.5, but didn't quite make it.
// Hope for better luck with 2.8 or later
/**
* Property that defines whether type serializer is allowed to omit writing
* of type id, in case that value written has type same as {@link #defaultImpl()}.
* If true, omission is allowed (although writer may or may not be able to do that);
* if false, type id should always be written still.
*
* @since 2.5
public boolean skipWritingDefault() default false;
*/

Copy link
Member

Choose a reason for hiding this comment

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

+1 for removal


/*
/**********************************************************
Expand All @@ -330,5 +330,22 @@ public enum As {
* if such behavior is needed; this is rarely necessary.
*/
@Deprecated
public abstract static class None { }
public abstract static class None {}

/**
* Specifies whether the type ID should be strictly required during polymorphic deserialization of its subtypes.
* <p>
* If set to {@link OptBoolean#TRUE}, an {@code InvalidTypeIdException} will be thrown if no type
* information is provided.
* If set to {@link OptBoolean#FALSE}, deserialization may proceed without type information if the
* subtype is a legitimate target (non-abstract).
* If set to {@link OptBoolean#DEFAULT}, the global configuration of
* {@code MapperFeature#REQUIRE_TYPE_ID_FOR_SUBTYPES} is used for type ID handling.
* <p>
* NOTE: This setting is specific to this type and will <strong>always override</strong> the global
* configuration of {@code MapperFeature#REQUIRE_TYPE_ID_FOR_SUBTYPES}.
*
* @since 2.16
*/
public OptBoolean requireTypeIdForSubtypes() default OptBoolean.DEFAULT;
}