1
1
/*
2
- * Copyright 2012-2024 the original author or authors.
2
+ * Copyright 2012-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -155,44 +155,56 @@ private class EntryBinder {
155
155
156
156
private final ResolvableType valueType ;
157
157
158
+ private final Class <?> resolvedValueType ;
159
+
160
+ private final boolean valueTreatedAsNestedMap ;
161
+
162
+ private final Bindable <Object > bindableMapType ;
163
+
164
+ private final Bindable <Object > bindableValueType ;
165
+
158
166
EntryBinder (ConfigurationPropertyName root , Bindable <?> target , AggregateElementBinder elementBinder ) {
159
167
this .root = root ;
160
168
this .elementBinder = elementBinder ;
161
169
this .mapType = target .getType ().asMap ();
162
170
this .keyType = this .mapType .getGeneric (0 );
163
171
this .valueType = this .mapType .getGeneric (1 );
172
+ this .resolvedValueType = this .valueType .resolve (Object .class );
173
+ this .valueTreatedAsNestedMap = Object .class .equals (this .resolvedValueType );
174
+ this .bindableMapType = Bindable .of (this .mapType );
175
+ this .bindableValueType = Bindable .of (this .valueType );
164
176
}
165
177
166
178
void bindEntries (ConfigurationPropertySource source , Map <Object , Object > map ) {
167
179
if (source instanceof IterableConfigurationPropertySource iterableSource ) {
168
180
for (ConfigurationPropertyName name : iterableSource ) {
169
- Bindable <?> valueBindable = getValueBindable (name );
170
181
ConfigurationPropertyName entryName = getEntryName (source , name );
171
182
Object key = getContext ().getConverter ().convert (getKeyName (entryName ), this .keyType );
183
+ Bindable <?> valueBindable = getValueBindable (name );
172
184
map .computeIfAbsent (key , (k ) -> this .elementBinder .bind (entryName , valueBindable ));
173
185
}
174
186
}
175
187
}
176
188
177
189
private Bindable <?> getValueBindable (ConfigurationPropertyName name ) {
178
- if (!this .root .isParentOf (name ) && isValueTreatedAsNestedMap ()) {
179
- return Bindable .of (this .mapType );
180
- }
181
- return Bindable .of (this .valueType );
190
+ return (!isParentOf (name ) && this .valueTreatedAsNestedMap ) ? this .bindableMapType : this .bindableValueType ;
182
191
}
183
192
184
193
private ConfigurationPropertyName getEntryName (ConfigurationPropertySource source ,
185
194
ConfigurationPropertyName name ) {
186
- Class <?> resolved = this .valueType .resolve (Object .class );
187
- if (Collection .class .isAssignableFrom (resolved ) || this .valueType .isArray ()) {
195
+ if (Collection .class .isAssignableFrom (this .resolvedValueType ) || this .valueType .isArray ()) {
188
196
return chopNameAtNumericIndex (name );
189
197
}
190
- if (!this . root . isParentOf (name ) && (isValueTreatedAsNestedMap () || !isScalarValue (source , name ))) {
198
+ if (!isParentOf (name ) && (this . valueTreatedAsNestedMap || !isScalarValue (source , name ))) {
191
199
return name .chop (this .root .getNumberOfElements () + 1 );
192
200
}
193
201
return name ;
194
202
}
195
203
204
+ private boolean isParentOf (ConfigurationPropertyName name ) {
205
+ return this .root .isParentOf (name );
206
+ }
207
+
196
208
private ConfigurationPropertyName chopNameAtNumericIndex (ConfigurationPropertyName name ) {
197
209
int start = this .root .getNumberOfElements () + 1 ;
198
210
int size = name .getNumberOfElements ();
@@ -204,10 +216,6 @@ private ConfigurationPropertyName chopNameAtNumericIndex(ConfigurationPropertyNa
204
216
return name ;
205
217
}
206
218
207
- private boolean isValueTreatedAsNestedMap () {
208
- return Object .class .equals (this .valueType .resolve (Object .class ));
209
- }
210
-
211
219
private boolean isScalarValue (ConfigurationPropertySource source , ConfigurationPropertyName name ) {
212
220
Class <?> resolved = this .valueType .resolve (Object .class );
213
221
if (!resolved .getName ().startsWith ("java.lang" ) && !resolved .isEnum ()) {
0 commit comments