-
-
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
[databind#4849] Allow standard defaultTyping with EnumSet<E>
#4857
Conversation
@@ -146,6 +146,11 @@ protected String _locateTypeId(JsonParser p, DeserializationContext ctxt) throws | |||
+ClassUtil.classNameOf(_idResolver)+") returned `null`"); | |||
} | |||
return id; | |||
} | |||
// [databind#4849] Since 2.18.3, Should maybe allow defaultTyping without defaultImpl if type is already known |
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.
@JooHyukKim Thinking this through, I don't think this is a proper fix, even tho it works around the specific failure here. I'll elaborate on the issue itself, but I think the problem may have been introduced by #4214 (in 2.17.0). Problem for tested case specifically is that customized DefaultTypeResolverBuilder
forces addition of type information for EVERY type (for whatever reason), due to:
@Override
public boolean useForType(JavaType t) {
return true;
}
Or, it should. But while EnumSetDeserializer
now expects polymorphic type id for EnumSet
AND every Enum
contained (... why is this desired?), I think EnumSetSerializer
does not write said type id. And I guess it should.
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.
Ah okay. Let's hold this for now. Will read through ur comment later.
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.
I committed my changes but it's very much work in progress. Too tired to continue for today, will pick up tomorrow :)
Ok: change the fix the way I think it might work -- solves the round-trip case, but serialization is different as type ids included for enum values. Might also consider opposite path of sort of undoing #4214 in part, maybe -- such that contents (Enums) of |
…s something wrt original problem
Ah ok. So the problem wrt #4214 -- after removing expectation of deserializer expecting type id -- is this:
So. Need to think of possible way to suppress Type Id inclusion for elements even with |
Changes needed bit too risky for a patch, moving target to |
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.
@cowtowncoder great work!
* during serialization: problem being that we can't always do it statically. | ||
* But we can figure out when there is a possibility wrt type signature we get. | ||
* | ||
* @since 2.18.3 |
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.
* @since 2.18.3 | |
* @since 2.19 |
Co-authored-by: Kim, Joo Hyuk <beanskobe@gmail.com>
// Unfortunately we can't check for EnumSet statically (if type indicated it, | ||
// we'd have constructed `EnumSetSerializer` instead). But we can check that | ||
// element type could possibly be an Enum. | ||
_maybeEnumSet = elemType.isEnumType() || elemType.isJavaLangObject(); |
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.
For 3.x version, would it be worth the effort trying to find other way instead of this?
And also parts with below code
// [databind#4849]/[databind#4214]: need to check for EnumSet
final TypeSerializer typeSer = (_maybeEnumSet && value instanceof EnumSet<?>)
? null : _valueTypeSerializer;
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.
If there is a way, sure, it would be great to get rid of this work-around.
But I am not sure how, considering the problem itself and how it occurs.
That is: I do not know how this could be avoided at all, regardless of compatibility concerns.
Ok. So, fix is quite ugly, but I cannot think of a cleaner way to achieve this. There was discrepancy b/w serialization (was not adding type id) vs deserialization (was expecting type id) in some cases. So, fix was also to remove earlier (#4214) changes that added type id handling for And why is type id not needed/wanted? Because for polymorphic typing we already have parent type id identified as something like Will merge into 2.19 due to somewhat extensive change; basically changes serialization of |
resolves #4849
possible backport to 2.17