mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-23 20:42:11 +00:00
Added simple fix for infinite recursion in entity mapping if class contains a field of same type as the class. In such case will skip that field.
This commit is contained in:
parent
61d8114513
commit
680e07726f
@ -25,7 +25,9 @@ import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.EMPTY;
|
||||
import static org.apache.commons.lang.StringUtils.isNotBlank;
|
||||
@ -57,14 +59,13 @@ class MappingBuilder {
|
||||
static XContentBuilder buildMapping(Class clazz, String indexType, String idFieldName) throws IOException {
|
||||
XContentBuilder xContentBuilder = jsonBuilder().startObject().startObject(indexType).startObject(FIELD_PROPERTIES);
|
||||
|
||||
mapEntity(xContentBuilder, clazz, true, idFieldName, EMPTY);
|
||||
mapEntity(xContentBuilder, clazz, true, idFieldName, EMPTY, new HashSet<Class>());
|
||||
|
||||
return xContentBuilder.endObject().endObject().endObject();
|
||||
}
|
||||
|
||||
private static void mapEntity(XContentBuilder xContentBuilder, Class clazz, boolean isRootObject, String idFieldName,
|
||||
String nestedObjectFieldName) throws IOException {
|
||||
|
||||
String nestedObjectFieldName, Set<Class> ancestorClasses) throws IOException {
|
||||
java.lang.reflect.Field[] fields = clazz.getDeclaredFields();
|
||||
|
||||
if (!isRootObject && isAnyPropertyAnnotatedAsField(fields)) {
|
||||
@ -78,7 +79,12 @@ class MappingBuilder {
|
||||
}
|
||||
|
||||
if (isEntity(field)) {
|
||||
mapEntity(xContentBuilder, field.getType(), false, EMPTY, field.getName());
|
||||
if (ancestorClasses.contains(field.getType())) {
|
||||
continue;
|
||||
} else {
|
||||
ancestorClasses.add(field.getType());
|
||||
mapEntity(xContentBuilder, field.getType(), false, EMPTY, field.getName(), ancestorClasses);
|
||||
}
|
||||
}
|
||||
|
||||
Field singleField = field.getAnnotation(Field.class);
|
||||
|
Loading…
x
Reference in New Issue
Block a user