DATACMNS-1102 - Reuse ConversionService in ProjectingMethodInterceptors created by ProxyProjectionFactory.
Applied the same to internals of MapDataBinder.
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.projection;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -27,7 +30,6 @@ import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -41,29 +43,12 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Oliver Gierke
|
||||
* @since 1.10
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
class ProjectingMethodInterceptor implements MethodInterceptor {
|
||||
|
||||
private final ProjectionFactory factory;
|
||||
private final MethodInterceptor delegate;
|
||||
private final ConversionService conversionService;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ProjectingMethodInterceptor} using the given {@link ProjectionFactory} and delegate
|
||||
* {@link MethodInterceptor}.
|
||||
*
|
||||
* @param factory the {@link ProjectionFactory} to use to create projections if types do not match, must not be
|
||||
* {@literal null}..
|
||||
* @param delegate the {@link MethodInterceptor} to trigger to create the source value, must not be {@literal null}..
|
||||
*/
|
||||
public ProjectingMethodInterceptor(ProjectionFactory factory, MethodInterceptor delegate) {
|
||||
|
||||
Assert.notNull(factory, "ProjectionFactory must not be null!");
|
||||
Assert.notNull(delegate, "Delegate MethodInterceptor must not be null!");
|
||||
|
||||
this.factory = factory;
|
||||
this.delegate = delegate;
|
||||
this.conversionService = new DefaultConversionService();
|
||||
}
|
||||
private final @NonNull ProjectionFactory factory;
|
||||
private final @NonNull MethodInterceptor delegate;
|
||||
private final @NonNull ConversionService conversionService;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
||||
@@ -28,6 +28,8 @@ import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.context.ResourceLoaderAware;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -49,6 +51,7 @@ class ProxyProjectionFactory implements ProjectionFactory, ResourceLoaderAware,
|
||||
ProxyProjectionFactory.class.getClassLoader());
|
||||
|
||||
private final List<MethodInterceptorFactory> factories;
|
||||
private final ConversionService conversionService;
|
||||
private ClassLoader classLoader;
|
||||
|
||||
/**
|
||||
@@ -59,6 +62,8 @@ class ProxyProjectionFactory implements ProjectionFactory, ResourceLoaderAware,
|
||||
this.factories = new ArrayList<>();
|
||||
this.factories.add(MapAccessingMethodInterceptorFactory.INSTANCE);
|
||||
this.factories.add(PropertyAccessingMethodInvokerFactory.INSTANCE);
|
||||
|
||||
this.conversionService = new DefaultConversionService();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,7 +181,7 @@ class ProxyProjectionFactory implements ProjectionFactory, ResourceLoaderAware,
|
||||
.createMethodInterceptor(source, projectionType);
|
||||
|
||||
return new ProjectingMethodInterceptor(this,
|
||||
postProcessAccessorInterceptor(propertyInvocationInterceptor, source, projectionType));
|
||||
postProcessAccessorInterceptor(propertyInvocationInterceptor, source, projectionType), conversionService);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user