@@ -108,13 +108,22 @@ public EntityIntrospectionResult(Class<?> entity) {
108
108
}
109
109
110
110
this .entity = entity ;
111
- this .descriptors = Stream .of (beanInfo .getPropertyDescriptors ())
112
- .map (AttributePropertyDescriptor ::new )
113
- .collect (Collectors .toMap (AttributePropertyDescriptor ::getName , it -> it ));
111
+
112
+ Map <String , PropertyDescriptor > map = Stream .of (beanInfo .getPropertyDescriptors ())
113
+ .collect (Collectors .toMap (PropertyDescriptor ::getName ,
114
+ Function .identity ()));
114
115
115
116
this .fields = getClasses ().flatMap (k -> Arrays .stream (k .getDeclaredFields ()))
116
- .filter (f -> descriptors .containsKey (Introspector .decapitalize (f .getName ())))
117
- .collect (Collectors .toMap (Field ::getName , it -> it ));
117
+ .filter (f -> map .containsKey (Introspector .decapitalize (f .getName ())))
118
+ .collect (Collectors .toMap (Field ::getName ,
119
+ Function .identity ()));
120
+
121
+ this .descriptors = map .values ()
122
+ .stream ()
123
+ .map (AttributePropertyDescriptor ::new )
124
+ .collect (Collectors .toMap (AttributePropertyDescriptor ::getName ,
125
+ Function .identity ()));
126
+
118
127
}
119
128
120
129
public Collection <AttributePropertyDescriptor > getPropertyDescriptors () {
@@ -168,9 +177,12 @@ public Stream<Class<?>> getClasses() {
168
177
public class AttributePropertyDescriptor {
169
178
170
179
private final PropertyDescriptor delegate ;
180
+ private final Optional <Field > field ;
171
181
172
182
public AttributePropertyDescriptor (PropertyDescriptor delegate ) {
173
183
this .delegate = delegate ;
184
+ this .field = Optional .ofNullable (fields .getOrDefault (getName (),
185
+ fields .get (capitalize (getName ()))));
174
186
}
175
187
176
188
public PropertyDescriptor getDelegate () {
@@ -185,16 +197,8 @@ public String getName() {
185
197
return delegate .getName ();
186
198
}
187
199
188
- private String getFieldName () {
189
- String name = getName ();
190
-
191
- return fields .containsKey (name )
192
- ? name
193
- : Character .toUpperCase (name .charAt (0 )) + name .substring (1 );
194
- }
195
-
196
200
public Optional <Field > getField () {
197
- return Optional . ofNullable ( fields . get ( getFieldName ())) ;
201
+ return field ;
198
202
}
199
203
200
204
public boolean hasField () {
@@ -344,5 +348,9 @@ public T next() {
344
348
Spliterators .spliteratorUnknownSize ( iterator , Spliterator .ORDERED | Spliterator .IMMUTABLE ),
345
349
false
346
350
);
347
- }
351
+ }
352
+
353
+ private static String capitalize (String str ) {
354
+ return Character .toUpperCase (str .charAt (0 )) + str .substring (1 );
355
+ }
348
356
}
0 commit comments