Skip to content

Commit 55ef6a9

Browse files
authored
Prep work for #5175: calc if prop-based Creator has any injectables (#5387)
1 parent d4f80c6 commit 55ef6a9

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ public Object getInjectableValueId() {
280280
return (_injectableValue == null) ? null : _injectableValue.getId();
281281
}
282282

283+
@Override // since 2.21
284+
public JacksonInject.Value getInjectionDefinition() {
285+
return _injectableValue;
286+
}
287+
283288
@Override
284289
public boolean isInjectionOnly() {
285290
return (_injectableValue != null) && !_injectableValue.willUseInput(true);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.lang.annotation.Annotation;
55

6+
import com.fasterxml.jackson.annotation.JacksonInject;
67
import com.fasterxml.jackson.core.*;
78
import com.fasterxml.jackson.databind.*;
89
import com.fasterxml.jackson.databind.deser.impl.FailingDeserializer;
@@ -468,6 +469,14 @@ public int getCreatorIndex() {
468469
*/
469470
public Object getInjectableValueId() { return null; }
470471

472+
/**
473+
* Accessor for injection definition, if this bean property supports
474+
* value injection.
475+
*
476+
* @since 2.21
477+
*/
478+
public JacksonInject.Value getInjectionDefinition() { return null; }
479+
471480
/**
472481
* Accessor for checking whether this property is injectable, and if so,
473482
* ONLY injectable (will not bind from input).

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ public final class PropertyBasedCreator
4545
*/
4646
protected final SettableBeanProperty[] _allProperties;
4747

48+
/**
49+
* Indexes of properties with associated Injectable values, if any:
50+
* {@code null} if none.
51+
*
52+
* @since 2.21
53+
*/
54+
protected final BitSet _injectablePropIndexes;
55+
4856
/*
4957
/**********************************************************
5058
/* Construction, initialization
@@ -61,11 +69,8 @@ protected PropertyBasedCreator(DeserializationContext ctxt,
6169
if (caseInsensitive) {
6270
_propertyLookup = CaseInsensitiveMap.construct(ctxt.getConfig().getLocale());
6371
} else {
64-
_propertyLookup = new HashMap<String, SettableBeanProperty>();
72+
_propertyLookup = new HashMap<>();
6573
}
66-
final int len = creatorProps.length;
67-
_propertyCount = len;
68-
_allProperties = new SettableBeanProperty[len];
6974

7075
// 26-Feb-2017, tatu: Let's start by aliases, so that there is no
7176
// possibility of accidental override of primary names
@@ -83,14 +88,27 @@ protected PropertyBasedCreator(DeserializationContext ctxt,
8388
}
8489
}
8590
}
91+
final int len = creatorProps.length;
92+
_propertyCount = len;
93+
_allProperties = new SettableBeanProperty[len];
94+
BitSet injectablePropIndexes = null;
95+
8696
for (int i = 0; i < len; ++i) {
8797
SettableBeanProperty prop = creatorProps[i];
8898
_allProperties[i] = prop;
8999
// 22-Jan-2018, tatu: ignorable entries should be skipped
90100
if (!prop.isIgnorable()) {
91101
_propertyLookup.put(prop.getName(), prop);
92102
}
103+
if (prop.getInjectionDefinition() != null) {
104+
if (injectablePropIndexes == null) {
105+
injectablePropIndexes = new BitSet(len);
106+
}
107+
injectablePropIndexes.set(i);
108+
}
93109
}
110+
111+
_injectablePropIndexes = injectablePropIndexes;
94112
}
95113

96114
/**
@@ -102,6 +120,7 @@ protected PropertyBasedCreator(PropertyBasedCreator base,
102120
{
103121
_propertyCount = base._propertyCount;
104122
_valueInstantiator = base._valueInstantiator;
123+
_injectablePropIndexes = base._injectablePropIndexes;
105124
_propertyLookup = propertyLookup;
106125
_allProperties = allProperties;
107126
}

0 commit comments

Comments
 (0)