-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 config-override for @JsonTypeInfo.Value
#3959
Add config-override for @JsonTypeInfo.Value
#3959
Conversation
src/test/java/com/fasterxml/jackson/databind/jsontype/PolymorphicHandlingOverrideTest.java
Outdated
Show resolved
Hide resolved
@JsonTypeInfo.Value
@JsonTypeInfo.Value
src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfig.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java
Outdated
Show resolved
Hide resolved
src/test/java/com/fasterxml/jackson/databind/introspect/TestAutoDetect.java
Outdated
Show resolved
Hide resolved
…on is that all subtypes come from databind itself
src/main/java/com/fasterxml/jackson/databind/jsontype/TypeResolverBuilder.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fasterxml/jackson/databind/jsontype/impl/StdTypeResolverBuilder.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java
Show resolved
Hide resolved
@Override | ||
public JsonTypeInfo.Value getDefaultPolymorphicTypeHandling(Class<?> baseType) | ||
{ | ||
ConfigOverride superOverride = _configOverrides.findOverride(baseType.getSuperclass()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok this is unfortunately problematic in couple of ways:
- It uses less specific (parent) information if both exist (should prefer specific one)
- Assumes 2 levels of inheritance (could have more)
- For interfaces
getSuperClass()
returnsnull
I think? I don't think this would work when base type is interface
It is also different from all other config overrides which only consider exact baseType
passed. I think that'd be correct thing to do here -- except I suspect there was a problem wrt serialization side: on deserialization one usually specifies proper base type (to get to polymorphic subtype). But on serialization, unfortunately, the way things are "baseType" is probably actual implementation type.
So using just that might not work.
If so I am not sure if this can actually be made to work, without fixing more fundamental problem: Jackson really should find proper base type on serialization too and not rely on annotation inheritance (which is why things work at all wrt @JsonTypeInfo
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But on serialization, unfortunately, the way things are "baseType" is probably actual implementation type. So using just that might not work.
Ah, okay. So this was what bothered me, but couldn't figure out why 😅. I should double check, if I remember correctly, the getSuperClass()
checking was needed on the serialization side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
problem: Jackson really should find proper base type on serialization too and not rely on annotation inheritance
@cowtowncoder Hmm unless there is a work going on about this, someday probably I will make time tacle this (or together if any). May I bring this up after your vacation (congrats😆)
Ok so I am bit worried about that issue I mentioned wrt locating |
At this point, I doubt.
Agreed, it seems like a dangerous path down 🙃... I will try to find cleaner way --plus after refering to other config-override mechanisms, it "might" be possible to make use of |
Temporarily draftedWill turn into draft until un-natural introspection at #3959 (comment) is resolved. |
Closing this as part of clean up, until solution is found 🙏🏼 |
@@ -875,6 +875,23 @@ public Boolean getDefaultMergeable(Class<?> baseType) { | |||
return _configOverrides.getDefaultMergeable(); | |||
} | |||
|
|||
// since 2.16 | |||
@Override | |||
public JsonTypeInfo.Value getDefaultPolymorphicTypeHandling(JavaType baseType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changed part since review #3959 (comment). Here we traverse using ClassUtil.findSuperTypes()
that supports both concrete types and interfaces.
EDIT : Traversal is to complement serialization side not locating the "exact" baseType.
WDYT? /cc @cowtowncoder
Closing for now. Because of low user demand AND |
JsonTypeInfo.Value
#3943