Skip to content

Commit

Permalink
Minor clean up post #3853
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 12, 2023
1 parent 5e2c643 commit f918d04
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
6 changes: 6 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1613,3 +1613,9 @@ Patrick Strawderman (kilink@github)
Matt Nelson (mattnelson@github)
* Requested #3814: Enhance `StdNodeBasedDeserializer` to support `readerForUpdating`
(2.15.0)
Steve Storey (stevestorey@github)
* Contributed #3853: Add `MapperFeature.REQUIRE_TYPE_ID_FOR_SUBTYPES` to enable/disable
strict subtype Type Id handling
(2.15.0)
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Not yet released
#3836: `Optional<Boolean>` is not recognized as boolean field
(reported by @thnaeff)
(fix contributed by Joo-Hyuk K)
#3853: Add `MapperFeature.REQUIRE_TYPE_ID_FOR_SUBTYPES` to enable/disable
strict subtype Type Id handling
(contributed by Steve S))

2.15.0-rc2 (28-Mar-2023)

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/fasterxml/jackson/databind/MapperFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,14 @@ public enum MapperFeature implements ConfigFeature
INFER_BUILDER_TYPE_BINDINGS(true),

/**
* Feature that determines what happens when deserializing to a registered sub-type, but no
* type information has been provided. If enabled, then an {@link InvalidTypeIdException}
* will be thrown, if disabled then the deserialization will proceed without the type information.
* Feature that determines what happens when deserializing to a registered sub-type
* (polymorphic deserialization), but no type information has been provided.
* If enabled, then an {@code InvalidTypeIdException} will be thrown;
* if disabled then the deserialization may proceed without the type information
* if sub-type is legit target (non-abstract).
*<p>
* Feature is enabled by default for backwards-compatibility (same behavior
* as in Jackson 2.14 and earlier).
*
* @since 2.15
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ public AsPropertyTypeDeserializer(JavaType bt, TypeIdResolver idRes,
String typePropertyName, boolean typeIdVisible, JavaType defaultImpl,
As inclusion)
{
super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl);
_inclusion = inclusion;
_strictTypeIdHandling = false;
this(bt, idRes, typePropertyName, typeIdVisible, defaultImpl, inclusion,
true);
}

public AsPropertyTypeDeserializer(AsPropertyTypeDeserializer src, BeanProperty property) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,14 @@ protected boolean _strictTypeIdHandling(DeserializationConfig config, JavaType b
if (config.isEnabled(MapperFeature.REQUIRE_TYPE_ID_FOR_SUBTYPES)) {
return true;
}
// Otherwise we will be strict if there's a type resolver
// Otherwise we will be strict if there's a type resolver: presumably
// target type is a (likely abstract) base type and cannot be used as target
return _hasTypeResolver(config, baseType);
}

/**
* Checks whether the given class has annotations indicating some type resolver
* is applied, for example {@link com.fasterxml.jackson.annotation.JsonSubTypes}.
* is applied, for example {@link com.fasterxml.jackson.annotation.JsonTypeInfo}.
* Only initializes {@link #_hasTypeResolver} once if its value is null.
*
* @param config the deserialization configuration to use
Expand Down

0 comments on commit f918d04

Please sign in to comment.