-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Allow introspection and polymorphic type handling to use JsonTypeInfo.Value
#3942
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
Closed
JooHyukKim
wants to merge
37
commits into
FasterXML:2.16
from
JooHyukKim:Introduce-JsonTypeInfo.Value
Closed
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
228bc0e
Add tests for `Record` deserialization regression and related (#3921)
JooHyukKim 79c232f
Backport findPolymorphicTypeInfo
JooHyukKim 8cabbd9
Clean up unnccessary change.
JooHyukKim 0b30af1
Use Value class around TypeResolverBuilder
JooHyukKim a509ac2
Clean up changes
JooHyukKim 97c14f1
Add version changes in StdTypeResolverBuilder
JooHyukKim 3b77339
Replace usage of TypeResolverBuilder.init
JooHyukKim 57b740e
Apply review
JooHyukKim 04b8ed2
Add behavioral test regarding `transient` field with annotation (#3951)
JooHyukKim 3505990
Update Maven wrapper version
cowtowncoder 8753e8a
Merge branch '2.15' into 2.16
cowtowncoder 58b9fc9
Backport `TypeResolverBuilder` initialization mechanisms from Jackson…
JooHyukKim cc02b19
remove obsolete "optimize" property
cowtowncoder a42a015
Start work on #3950: add skeletal IterationType (to merge to 3.0)
cowtowncoder dcffc41
Minor removal of deprecated "narrow" method implementation from JavaT…
cowtowncoder f878a66
...
cowtowncoder 9991ffc
Backport findPolymorphicTypeInfo
JooHyukKim 3cb02a4
Clean up unnccessary change.
JooHyukKim bcb1c27
Use Value class around TypeResolverBuilder
JooHyukKim 0d472b3
Clean up changes
JooHyukKim 8d63f67
Add version changes in StdTypeResolverBuilder
JooHyukKim 94a66c6
Replace usage of TypeResolverBuilder.init
JooHyukKim 3d5d2a8
Apply review
JooHyukKim c30d8a6
Remove unnccessary changes
JooHyukKim 93983d3
Merge branch 'Introduce-JsonTypeInfo.Value' of https://github.com/Joo…
JooHyukKim 3761d1b
Remove conflicting change in TypeResolverBuilder
JooHyukKim 90edb76
Revert "Merge branch 'Introduce-JsonTypeInfo.Value' of https://github…
JooHyukKim 7fdc0e7
Backport findPolymorphicTypeInfo
JooHyukKim d8d3990
Clean up unnccessary change.
JooHyukKim dd6054a
Use Value class around TypeResolverBuilder
JooHyukKim 4386503
Clean up changes
JooHyukKim e628ddc
Add version changes in StdTypeResolverBuilder
JooHyukKim 5e5d3b4
Replace usage of TypeResolverBuilder.init
JooHyukKim 669ca81
Apply review
JooHyukKim deee3a9
Remove conflicting change in TypeResolverBuilder
JooHyukKim 176d904
Revert "Merge branch 'Introduce-JsonTypeInfo.Value' of https://github…
JooHyukKim c200afd
Merge branch 'Introduce-JsonTypeInfo.Value' of https://github.com/Joo…
JooHyukKim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.fasterxml.jackson.databind.jsontype.impl; | ||
|
||
import com.fasterxml.jackson.databind.introspect.Annotated; | ||
import java.util.Collection; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
|
@@ -35,6 +36,11 @@ public class StdTypeResolverBuilder | |
*/ | ||
protected boolean _typeIdVisible = false; | ||
|
||
/** | ||
* @since 2.16 (backported from Jackson 3.0) | ||
*/ | ||
protected Boolean _requireTypeIdForSubtypes; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this field should be included in this PR, but #3891 |
||
|
||
/** | ||
* Default class to use in case type information is not available | ||
* or is broken. | ||
|
@@ -78,10 +84,40 @@ protected StdTypeResolverBuilder(StdTypeResolverBuilder base, | |
_customIdResolver = base._customIdResolver; | ||
|
||
_defaultImpl = defaultImpl; | ||
_requireTypeIdForSubtypes = base._requireTypeIdForSubtypes; | ||
} | ||
|
||
/** | ||
* @since 2.16 (backported from Jackson 3.0) | ||
*/ | ||
public StdTypeResolverBuilder(JsonTypeInfo.Value settings) { | ||
if (settings != null) { | ||
_idType = settings.getIdType(); | ||
if (_idType == null) { | ||
throw new IllegalArgumentException("idType cannot be null"); | ||
} | ||
_includeAs = settings.getInclusionType(); | ||
_typeProperty = _propName(settings.getPropertyName(), _idType); | ||
_defaultImpl = settings.getDefaultImpl(); | ||
_typeIdVisible = settings.getIdVisible(); | ||
_requireTypeIdForSubtypes = settings.getRequireTypeIdForSubtypes(); | ||
} | ||
} | ||
|
||
/** | ||
* @since 2.16 (backported from Jackson 3.0) | ||
*/ | ||
protected static String _propName(String propName, JsonTypeInfo.Id idType) { | ||
if (propName == null) { | ||
propName = idType.getDefaultPropertyName(); | ||
} | ||
return propName; | ||
} | ||
|
||
public static StdTypeResolverBuilder noTypeInfoBuilder() { | ||
return new StdTypeResolverBuilder().init(JsonTypeInfo.Id.NONE, null); | ||
JsonTypeInfo.Value typeInfo = JsonTypeInfo.Value.construct(JsonTypeInfo.Id.NONE, null, | ||
null, null, false, null); | ||
return new StdTypeResolverBuilder().init(typeInfo, null); | ||
} | ||
|
||
@Override | ||
|
@@ -98,6 +134,31 @@ public StdTypeResolverBuilder init(JsonTypeInfo.Id idType, TypeIdResolver idRes) | |
return this; | ||
} | ||
|
||
@Override | ||
public StdTypeResolverBuilder init(JsonTypeInfo.Value settings, | ||
TypeIdResolver idRes) | ||
{ | ||
_customIdResolver = idRes; | ||
|
||
if (settings != null) { | ||
_idType = settings.getIdType(); | ||
if (_idType == null) { | ||
throw new IllegalArgumentException("idType cannot be null"); | ||
} | ||
_includeAs = settings.getInclusionType(); | ||
|
||
// Let's also initialize property name as per idType default | ||
_typeProperty = settings.getPropertyName(); | ||
if (_typeProperty == null) { | ||
_typeProperty = _idType.getDefaultPropertyName(); | ||
} | ||
_typeIdVisible = settings.getIdVisible(); | ||
_defaultImpl = settings.getDefaultImpl(); | ||
_requireTypeIdForSubtypes = settings.getRequireTypeIdForSubtypes(); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public TypeSerializer buildTypeSerializer(SerializationConfig config, | ||
JavaType baseType, Collection<NamedType> subtypes) | ||
|
@@ -436,11 +497,11 @@ protected boolean _strictTypeIdHandling(DeserializationConfig config, JavaType b | |
* | ||
* @return true if the class has type resolver annotations, false otherwise | ||
* | ||
* @since 2.15 | ||
* @since 2.15, using {@code ai.findPolymorphicTypeInfo(config, ac)} since 2.16. | ||
*/ | ||
protected boolean _hasTypeResolver(DeserializationConfig config, JavaType baseType) { | ||
AnnotatedClass ac = AnnotatedClassResolver.resolveWithoutSuperTypes(config, baseType.getRawClass()); | ||
AnnotationIntrospector ai = config.getAnnotationIntrospector(); | ||
return ai.findTypeResolver(config, ac, baseType) != null; | ||
return ai.findPolymorphicTypeInfo(config, ac) != null; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/fasterxml/jackson/databind/type/IterationType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.fasterxml.jackson.databind.type; | ||
|
||
import com.fasterxml.jackson.databind.JavaType; | ||
|
||
/** | ||
* Specialized {@link SimpleType} for types that are allow iteration | ||
* over Collection(-like) types: this includes types like | ||
* {@link java.util.Iterator}. | ||
* Referenced type is accessible using {@link #getContentType()}. | ||
* | ||
* @since 2.16 | ||
*/ | ||
public abstract class IterationType extends SimpleType | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
protected final JavaType _iteratedType; | ||
|
||
/** | ||
* Constructor used when upgrading into this type (via {@link #upgradeFrom}, | ||
* the usual way for {@link IterationType}s to come into existence. | ||
* Sets up what is considered the "base" reference type | ||
*/ | ||
protected IterationType(TypeBase base, JavaType iteratedType) | ||
{ | ||
super(base); | ||
_iteratedType = iteratedType; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.