Skip to content

Commit a5c99a1

Browse files
committed
DATAES-325 - Replace references to GenericCollectionTypeResolver with ResolvableType.
Using ResolvableType instead of GenericCollectionTypeResolver that is removed with Spring 5. Related ticket: SPR-15160.
1 parent 7eb297a commit a5c99a1

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2016 the original author or authors.
2+
* Copyright 2014-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
2828
import org.apache.commons.lang.StringUtils;
2929
import org.apache.commons.lang.math.NumberUtils;
3030
import org.elasticsearch.common.xcontent.XContentBuilder;
31-
import org.springframework.core.GenericCollectionTypeResolver;
31+
import org.springframework.core.ResolvableType;
3232
import org.springframework.core.io.ClassPathResource;
3333
import org.springframework.data.annotation.Transient;
3434
import org.springframework.data.elasticsearch.annotations.*;
@@ -47,8 +47,8 @@
4747
* @author Alexander Volz
4848
* @author Dennis Maaß
4949
* @author Pavel Luhin
50+
* @author Mark Paluch
5051
*/
51-
5252
class MappingBuilder {
5353

5454
public static final String FIELD_STORE = "store";
@@ -315,12 +315,20 @@ protected static boolean isEntity(java.lang.reflect.Field field) {
315315
}
316316

317317
protected static Class<?> getFieldType(java.lang.reflect.Field field) {
318-
Class<?> clazz = field.getType();
319-
TypeInformation typeInformation = ClassTypeInformation.from(clazz);
320-
if (typeInformation.isCollectionLike()) {
321-
clazz = GenericCollectionTypeResolver.getCollectionFieldType(field) != null ? GenericCollectionTypeResolver.getCollectionFieldType(field) : typeInformation.getComponentType().getType();
318+
319+
ResolvableType resolvableType = ResolvableType.forField(field);
320+
321+
if (resolvableType.isArray()) {
322+
return resolvableType.getComponentType().getRawClass();
322323
}
323-
return clazz;
324+
325+
ResolvableType componentType = resolvableType.getGeneric(0);
326+
if (Iterable.class.isAssignableFrom(field.getType())
327+
&& componentType != ResolvableType.NONE) {
328+
return componentType.getRawClass();
329+
}
330+
331+
return resolvableType.getRawClass();
324332
}
325333

326334
private static boolean isAnyPropertyAnnotatedAsField(java.lang.reflect.Field[] fields) {

0 commit comments

Comments
 (0)