FasterXML / jackson-databind

General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)
Apache License 2.0
3.52k stars 1.38k forks source link

JacksonInject strangeness #471

Closed pfumagalli closed 10 years ago

pfumagalli commented 10 years ago

See discussion on the mailing list.

Basically, when a constructor is annotated with @JsonCreator, any field or method annotated with @JacksonInject gets ignored.

In version 2.3.3 this happens because at line 268 the deserializeFromObject(...) method simply returns:

return deserializeFromObjectUsingNonDefault(jp, ctxt);

I fixed it locally by copying some code from below:

Object bean = deserializeFromObjectUsingNonDefault(jp, ctxt);
if (_injectables != null) {
    injectValues(ctxt, bean);
}
if (_needViewProcesing) {
    Class<?> view = ctxt.getActiveView();
    if (view != null) {
        return deserializeWithView(jp, ctxt, bean, view);
    }
}
return bean;
pfumagalli commented 10 years ago

Patch against 2.3.3:

--- ./orig/com/fasterxml/jackson/databind/deser/BeanDeserializer.java   2014-04-10 09:54:44.000000000 +0900
+++ ./fix/main/com/fasterxml/jackson/databind/deser/BeanDeserializer.java   2014-05-26 15:07:43.000000000 +0900
@@ -263,11 +273,22 @@
                 return deserializeWithUnwrapped(jp, ctxt);
             }
             if (_externalTypeIdHandler != null) {
                 return deserializeWithExternalTypeId(jp, ctxt);
             }
-            return deserializeFromObjectUsingNonDefault(jp, ctxt);
+
+            Object bean = deserializeFromObjectUsingNonDefault(jp, ctxt);
+            if (_injectables != null) {
+                injectValues(ctxt, bean);
+            }
+            if (_needViewProcesing) {
+                Class<?> view = ctxt.getActiveView();
+                if (view != null) {
+                    return deserializeWithView(jp, ctxt, bean, view);
+                }
+            }
+            return bean;
         }
         final Object bean = _valueInstantiator.createUsingDefault(ctxt);
         if (jp.canReadObjectId()) {
             Object id = jp.getObjectId();
             if (id != null) {
pfumagalli commented 10 years ago

Whops, sorry for the duplicate issue.

See the pull request.