Skip to content
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

Annotation-provided Deserializers are not contextualized inside CreatorProperties #462

Closed
aarondav opened this issue May 19, 2014 · 4 comments
Milestone

Comments

@aarondav
Copy link
Contributor

On this line within BasicDeserializerFactory#constructCreatorProperty, we create a Deserializer based on an annotation:

JsonDeserializer<Object> deser = findDeserializerFromAnnotation(ctxt, param);
... // lines that do not reference "deser"
if (deser != null) {
    prop = prop.withValueDeserializer(deser);
}

(source)

findDeserializerFromAnnotation will resolve, but not contextualize, the resulting Deserializer. Subsequently, in PropertyBasedCreator#construct, we will construct a contextualized Deserializer if and only if a Deserializer is not already present:

if (!prop.hasValueDeserializer()) {
    prop = prop.withValueDeserializer(ctxt.findContextualValueDeserializer(prop.getType(), prop));
}

(source)

However, this returns false because we do have a value deserializer.

Finally, we attempt to deserialize using this PropertyBasedCreator, within BeanDeserializer#_deserializeUsingPropertyBased:

Object value = creatorProp.deserialize(jp, ctxt);

(source)

This fails, however, as our Deserializer was never contextualized.

If this is indeed a bug, I think a simple fix may be to simply contextualize the Deserializer within PropertyBasedCreator#construct if it's present. Let me know if that is a good solution; I can make a PR if desired.

@cowtowncoder
Copy link
Member

Yes, it sounds like a bug: all serializers/deserializers should be contextualized (when used for a property, i.e. when there is a context). Thanks; I will fix this.

cowtowncoder added a commit that referenced this issue May 20, 2014
@cowtowncoder cowtowncoder added this to the 2.3.4 milestone May 20, 2014
@cowtowncoder
Copy link
Member

Added a call to contextualization; will be in 2.3.4 / 2.4.0. If you have a chance to verify from either, that'd be great, but I assume that problem is resolved.

cowtowncoder added a commit that referenced this issue May 20, 2014
@aarondav
Copy link
Contributor Author

I have verified the fix in 2.3.4-SNAPSHOT. Thanks a bunch for the quick patch! @JsonDefaultValue is now more easily implementable for the Scala case class junkies among us... :)

What is the release schedule for 2.3.4?

@cowtowncoder
Copy link
Member

I am hoping to get 2.4.0 first; there are some patches for 2.3.4, but it will probably take at least couple of weeks.

Thank you for verifying this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants