Skip to content

Commit 8d76185

Browse files
committed
Partial commit of #5175 (for #1381)
1 parent f47b7b3 commit 8d76185

File tree

10 files changed

+50
-26
lines changed

10 files changed

+50
-26
lines changed

release-notes/CREDITS-2.x

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ wrongwrong (@k163377)
18661866
* Contributed fix for #5139: In `CollectionDeserializer`, `JsonSetter.contentNulls`
18671867
is sometimes ignored
18681868
(2.19.1)
1869-
* Contributed fix for #5202: #5202: `JsonSetter.contentNulls` ignored for `Object[]`,
1869+
* Contributed fix for #5202: `JsonSetter.contentNulls` ignored for `Object[]`,
18701870
`String[]` and `Collection<String>`
18711871
(2.19.2)
18721872
* Reported #4218: If `@JacksonInject` is specified for field and deserialized by
@@ -1955,8 +1955,8 @@ Eddú Meléndez Gonzales (@eddumelendez)
19551955
(2.19.2)
19561956
19571957
Giulio Longfils (@giulong)
1958-
* Contributed #2678: `@JacksonInject` added to property overrides value from the JSON
1959-
even if `useInput` is `OptBoolean.TRUE`
1958+
* Contributed fix for #2678: `@JacksonInject` added to property overrides value
1959+
from the JSON even if `useInput` is `OptBoolean.TRUE`
19601960
(2.20.0)
19611961
* Contributed #3072: Allow specifying `@JacksonInject` does not fail when there's no
19621962
corresponding value

src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ public final boolean hasSomeOfFeatures(int featureMask) {
465465
* @since 2.20
466466
*/
467467
public final Object findInjectableValue(Object valueId,
468-
BeanProperty forProperty, Object beanInstance, Boolean optional)
468+
BeanProperty forProperty, Object beanInstance, Boolean optional, Boolean useInput)
469469
throws JsonMappingException
470470
{
471471
if (_injectableValues == null) {
@@ -479,7 +479,8 @@ public final Object findInjectableValue(Object valueId,
479479
"No 'injectableValues' configured, cannot inject value with id '%s'", valueId),
480480
valueId, forProperty, beanInstance);
481481
}
482-
return _injectableValues.findInjectableValue(this, valueId, forProperty, beanInstance, optional);
482+
return _injectableValues.findInjectableValue(this, valueId, forProperty, beanInstance,
483+
optional, useInput);
483484
}
484485

485486
/**
@@ -490,7 +491,7 @@ public final Object findInjectableValue(Object valueId,
490491
BeanProperty forProperty, Object beanInstance)
491492
throws JsonMappingException
492493
{
493-
return findInjectableValue(valueId, forProperty, beanInstance, null);
494+
return findInjectableValue(valueId, forProperty, beanInstance, null, null);
494495
}
495496

496497
/**

src/main/java/com/fasterxml/jackson/databind/InjectableValues.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public abstract class InjectableValues
3030
*/
3131
public Object findInjectableValue(DeserializationContext ctxt,
3232
Object valueId, BeanProperty forProperty, Object beanInstance,
33-
Boolean optional)
33+
Boolean optional, Boolean useInput)
3434
throws JsonMappingException
3535
{
3636
// For backwards-compatibility, must delegate to old method
@@ -42,7 +42,8 @@ public Object findInjectableValue(DeserializationContext ctxt,
4242
*/
4343
@Deprecated // since 2.20
4444
public abstract Object findInjectableValue(Object valueId, DeserializationContext ctxt,
45-
BeanProperty forProperty, Object beanInstance) throws JsonMappingException;
45+
BeanProperty forProperty, Object beanInstance)
46+
throws JsonMappingException;
4647

4748
/*
4849
/**********************************************************
@@ -85,7 +86,8 @@ public Std addValue(Class<?> classKey, Object value) {
8586
*/
8687
@Override
8788
public Object findInjectableValue(DeserializationContext ctxt, Object valueId,
88-
BeanProperty forProperty, Object beanInstance, Boolean optional)
89+
BeanProperty forProperty, Object beanInstance,
90+
Boolean optional, Boolean useInput)
8991
throws JsonMappingException
9092
{
9193
if (!(valueId instanceof String)) {
@@ -116,9 +118,11 @@ public Object findInjectableValue(DeserializationContext ctxt, Object valueId,
116118
@Override
117119
@Deprecated // since 2.20
118120
public Object findInjectableValue(Object valueId, DeserializationContext ctxt,
119-
BeanProperty forProperty, Object beanInstance) throws JsonMappingException
121+
BeanProperty forProperty, Object beanInstance)
122+
throws JsonMappingException
120123
{
121-
return this.findInjectableValue(ctxt, valueId, forProperty, beanInstance, null);
124+
return this.findInjectableValue(ctxt, valueId, forProperty, beanInstance,
125+
null, null);
122126
}
123127
}
124128
}

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public void addBackReferenceProperty(String referenceName, SettableBeanProperty
244244
*/
245245
public void addInjectable(PropertyName propName, JavaType propType,
246246
Annotations contextAnnotations, AnnotatedMember member,
247-
Object valueId, Boolean optional)
247+
Object valueId, Boolean optional, Boolean useInput)
248248
throws JsonMappingException
249249
{
250250
if (_injectables == null) {
@@ -257,7 +257,7 @@ public void addInjectable(PropertyName propName, JavaType propType,
257257
_handleBadAccess(e);
258258
}
259259
}
260-
_injectables.add(new ValueInjector(propName, propType, member, valueId, optional));
260+
_injectables.add(new ValueInjector(propName, propType, member, valueId, optional, useInput));
261261
}
262262

263263
/**
@@ -269,7 +269,7 @@ public void addInjectable(PropertyName propName, JavaType propType,
269269
Object valueId)
270270
throws JsonMappingException
271271
{
272-
this.addInjectable(propName, propType, contextAnnotations, member, valueId, null);
272+
this.addInjectable(propName, propType, contextAnnotations, member, valueId, null, null);
273273
}
274274

275275
/**

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,11 +822,18 @@ protected void addInjectables(DeserializationContext ctxt,
822822
for (Map.Entry<Object, AnnotatedMember> entry : raw.entrySet()) {
823823
AnnotatedMember m = entry.getValue();
824824
final JacksonInject.Value injectableValue = introspector.findInjectableValue(m);
825-
final Boolean optional = injectableValue == null ? null : injectableValue.getOptional();
826-
825+
final Boolean optional, useInput;
826+
827+
if (injectableValue == null) {
828+
optional = useInput = null;
829+
} else {
830+
optional = injectableValue.getOptional();
831+
useInput = injectableValue.getUseInput();
832+
}
827833
builder.addInjectable(PropertyName.construct(m.getName()),
828834
m.getType(),
829-
beanDesc.getClassAnnotations(), m, entry.getKey(), optional);
835+
beanDesc.getClassAnnotations(), m, entry.getKey(),
836+
optional, useInput);
830837
}
831838
}
832839
}

src/main/java/com/fasterxml/jackson/databind/deser/impl/PropertyValueBuffer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.fasterxml.jackson.databind.*;
88
import com.fasterxml.jackson.databind.deser.*;
99
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
10-
import com.fasterxml.jackson.databind.util.ClassUtil;
1110
import com.fasterxml.jackson.databind.util.TokenBuffer;
1211

1312
/**
@@ -270,7 +269,7 @@ protected Object _findMissing(SettableBeanProperty prop) throws JsonMappingExcep
270269
Object injectableValueId = prop.getInjectableValueId();
271270
if (injectableValueId != null) {
272271
return _context.findInjectableValue(prop.getInjectableValueId(),
273-
prop, null, null);
272+
prop, null, null, null);
274273
}
275274
// Second: required?
276275
if (prop.isRequired()) {

src/main/java/com/fasterxml/jackson/databind/deser/impl/ValueInjector.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,24 @@ public class ValueInjector
2929
*/
3030
protected final Boolean _optional;
3131

32+
/**
33+
* Flag used for configuring the behavior when the input value should be preferred
34+
* over the value to inject.
35+
*
36+
* @since 2.20
37+
*/
38+
protected final Boolean _useInput;
39+
3240
/**
3341
* @since 2.20
3442
*/
3543
public ValueInjector(PropertyName propName, JavaType type,
36-
AnnotatedMember mutator, Object valueId, Boolean optional)
44+
AnnotatedMember mutator, Object valueId, Boolean optional, Boolean useInput)
3745
{
3846
super(propName, type, null, mutator, PropertyMetadata.STD_OPTIONAL);
3947
_valueId = valueId;
4048
_optional = optional;
49+
_useInput = useInput;
4150
}
4251

4352
/**
@@ -47,13 +56,13 @@ public ValueInjector(PropertyName propName, JavaType type,
4756
public ValueInjector(PropertyName propName, JavaType type,
4857
AnnotatedMember mutator, Object valueId)
4958
{
50-
this(propName, type, mutator, valueId, null);
59+
this(propName, type, mutator, valueId, null, null);
5160
}
5261

5362
public Object findValue(DeserializationContext context, Object beanInstance)
5463
throws JsonMappingException
5564
{
56-
return context.findInjectableValue(_valueId, this, beanInstance, _optional);
65+
return context.findInjectableValue(_valueId, this, beanInstance, _optional, _useInput);
5766
}
5867

5968
public void inject(DeserializationContext context, Object beanInstance)

src/main/java/com/fasterxml/jackson/databind/deser/std/StdValueInstantiator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,9 @@ private Object _createUsingDelegate(AnnotatedWithParams delegateCreator,
674674
args[i] = delegate;
675675
} else { // nope, injectable:
676676
// 09-May-2025, tatu: Not sure where to get "optional" (last arg) value...
677-
args[i] = ctxt.findInjectableValue(prop.getInjectableValueId(), prop, null, null);
677+
// 25-Aug-2025, tatu: ... or "useInput"
678+
args[i] = ctxt.findInjectableValue(prop.getInjectableValueId(), prop,
679+
null, null, null);
678680
}
679681
}
680682
// and then try calling with full set of arguments

src/test/java/com/fasterxml/jackson/databind/deser/inject/JacksonInject4218Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public Object findInjectableValue(
3939
Object valueId,
4040
BeanProperty forProperty,
4141
Object beanInstance,
42-
Boolean optional
42+
Boolean optional, Boolean useInput
4343
) throws JsonMappingException {
4444
if (valueId.equals("id")) {
4545
return "id" + nextId++;
4646
} else {
47-
return super.findInjectableValue(ctxt, valueId, forProperty, beanInstance, optional);
47+
return super.findInjectableValue(ctxt, valueId, forProperty, beanInstance, optional, useInput);
4848
}
4949
}
5050
}

src/test/java/com/fasterxml/jackson/databind/introspect/IntrospectorPairTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,8 @@ static class TestInjector extends InjectableValues {
699699
@Override
700700
public Object findInjectableValue(DeserializationContext ctxt,
701701
Object valueId,
702-
BeanProperty forProperty, Object beanInstance, Boolean optional) {
702+
BeanProperty forProperty, Object beanInstance,
703+
Boolean optional, Boolean useInput) {
703704
if (valueId == "jjj") {
704705
UnreadableBean bean = new UnreadableBean();
705706
bean.setValue(1);
@@ -708,6 +709,7 @@ public Object findInjectableValue(DeserializationContext ctxt,
708709
return null;
709710
}
710711

712+
@Deprecated // since 2.20
711713
@Override
712714
public Object findInjectableValue(Object valueId, DeserializationContext ctxt,
713715
BeanProperty forProperty, Object beanInstance) {

0 commit comments

Comments
 (0)