-
-
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
Fix issues 4697 and 2461 (@JsonUnwrapped
caching)
#4722
Conversation
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.
Added a few notes, thanks!
src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyWriter.java
Outdated
Show resolved
Hide resolved
@@ -459,7 +470,7 @@ Object readResolve() { | |||
_field = null; | |||
} | |||
if (_serializer == null) { | |||
_dynamicSerializers = PropertySerializerMap.emptyForProperties(); | |||
_dynamicSerializers = emptyForProperties(); |
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.
Here also, unncessary change (at least for this PR).
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.
done, though it was a clean way to import statically
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 prefer avoiding static imports for method calls fwtw. Maybe that should be added in style guide (or maybe it is mentioned and CONTRIBUTING.md should refer). I know IDEs can show where method comes from but for me (and I realize this is matter of preference) little bit of redundancy can be helpful.
if(base instanceof UnwrappingBeanPropertyWriter) { | ||
_dynamicSerializers = | ||
emptyForProperties(); | ||
} else { | ||
_dynamicSerializers = base._dynamicSerializers; | ||
} |
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.
Keep the format consistent.
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.
Agreed, I will set the formatter.
if(base instanceof UnwrappingBeanPropertyWriter) { | ||
_dynamicSerializers = | ||
emptyForProperties(); | ||
} else { | ||
_dynamicSerializers = base._dynamicSerializers; | ||
} | ||
_suppressNulls = base._suppressNulls; |
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.
Formatting needs to be done.
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.
done
@@ -325,7 +326,12 @@ protected BeanPropertyWriter(BeanPropertyWriter base, PropertyName name) { | |||
base._internalSettings); | |||
} | |||
_cfgSerializationType = base._cfgSerializationType; | |||
_dynamicSerializers = base._dynamicSerializers; | |||
if(base instanceof UnwrappingBeanPropertyWriter) { |
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.
Dependency from super class to subclasses doesn't seem to be the right direction.
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.
Yes, did the same thing in a better way now
_dynamicSerializers = PropertySerializerMap.emptyForProperties(); | ||
} else { | ||
_dynamicSerializers = base._dynamicSerializers; | ||
} | ||
_suppressNulls = base._suppressNulls; |
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.
Where are these constructors called? Does this mean serializer information from 'base' should be lost?
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.
_dynamicSerializers
is purely performance optimization, caching to avoid unnecessary full introspection -- should never be needed for correctness. Hence if necessary we can just use empty instance for copy constructors.
@@ -325,7 +326,11 @@ protected BeanPropertyWriter(BeanPropertyWriter base, PropertyName name) { | |||
base._internalSettings); | |||
} | |||
_cfgSerializationType = base._cfgSerializationType; | |||
_dynamicSerializers = base._dynamicSerializers; | |||
if (base.needToResetSerialization()) { |
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 am not sure check is needed, should probably simply reset always; I'll add a general note to PR.
@@ -100,6 +100,13 @@ public <A extends Annotation> A findAnnotation(Class<A> acls) { | |||
/********************************************************** | |||
*/ | |||
|
|||
/** | |||
* A way to reset serialization to correctly populate serializer |
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.
This unfortunately doesn't really describe anything....
Ok: first of all, yes, it does sound like (and makes sense, too) that the issue is incorrect caching of resolved serializers: Alternatively there is an existing method But it seems to me simplest to just re-initialize -- empty instances are shared stateless singletons so there's no real cost for constructing. And in most cases this makes no difference anyway. |
Hi, Thanks, |
Ok, happy to merge this fix. Just one process thing first: since this is (I think) your first contribution, we'd need CLA from: https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf (this only needs to be done once before the first PR gets merged -- one is good for all future PRs). It is usually easiest to print, fill & sign, scan/photo, email to Thank you again @SandeepGaur2016 for the contribution! |
@JsonUnwrapped
caching)
I have sent the CLA form. Thanks, |
CLA received, can proceed! |
I recently raised a bug (4697) and have now had some time to investigate the issue. Although this is my first contribution, I noticed that when we obtain a serializer from the case, the name transformation is reset in the _findAndAddDynamic method of UnwrappingBeanPropertyWriter. However, this method does not account for inner or nested properties. I have implemented a fix to reinitialize the serializer in such cases.
It has also fixed looks same issue from raised earlier (#2461)
Thanks,
Sandeep Gaur