Skip to content

Commit 156f7c3

Browse files
Tomasz Wysockiodrotbohm
Tomasz Wysocki
authored andcommitted
DATACMNS-693 - AbstractMappingContext now uses Spring's BeanUtils to lookup PropertyDescriptors.
Instead of manually using Introspector.getBeanInfo(…) we now use Spring's BeanUtils.getPropertyDescriptors(…) to benefit from some caching of descriptor instances as well as advanced support for fluent setters, default methods etc. Original pull request: #122.
1 parent e70cfbf commit 156f7c3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
*/
1616
package org.springframework.data.mapping.context;
1717

18-
import java.beans.BeanInfo;
19-
import java.beans.IntrospectionException;
20-
import java.beans.Introspector;
2118
import java.beans.PropertyDescriptor;
2219
import java.lang.reflect.Field;
2320
import java.lang.reflect.Modifier;
@@ -34,6 +31,8 @@
3431
import java.util.concurrent.locks.Lock;
3532
import java.util.concurrent.locks.ReentrantReadWriteLock;
3633

34+
import org.springframework.beans.BeanUtils;
35+
import org.springframework.beans.BeansException;
3736
import org.springframework.beans.factory.InitializingBean;
3837
import org.springframework.context.ApplicationEventPublisher;
3938
import org.springframework.context.ApplicationEventPublisherAware;
@@ -63,6 +62,7 @@
6362
* @author Oliver Gierke
6463
* @author Michael Hunger
6564
* @author Thomas Darimont
65+
* @author Tomasz Wysocki
6666
*/
6767
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?, P>, P extends PersistentProperty<P>>
6868
implements MappingContext<E, P>, ApplicationEventPublisherAware, InitializingBean {
@@ -281,10 +281,10 @@ protected E addPersistentEntity(TypeInformation<?> typeInformation) {
281281
// Eagerly cache the entity as we might have to find it during recursive lookups.
282282
persistentEntities.put(typeInformation, entity);
283283

284-
BeanInfo info = Introspector.getBeanInfo(type);
284+
PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(type);
285285

286286
final Map<String, PropertyDescriptor> descriptors = new HashMap<String, PropertyDescriptor>();
287-
for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) {
287+
for (PropertyDescriptor descriptor : pds) {
288288
descriptors.put(descriptor.getName(), descriptor);
289289
}
290290

@@ -308,7 +308,7 @@ protected E addPersistentEntity(TypeInformation<?> typeInformation) {
308308

309309
return entity;
310310

311-
} catch (IntrospectionException e) {
311+
} catch (BeansException e) {
312312
throw new MappingException(e.getMessage(), e);
313313
} finally {
314314
write.unlock();

0 commit comments

Comments
 (0)