25
25
import org .springframework .data .util .TypeInformation ;
26
26
27
27
import java .io .IOException ;
28
+ import java .util .HashSet ;
28
29
import java .util .Map ;
30
+ import java .util .Set ;
29
31
30
32
import static org .apache .commons .lang .StringUtils .EMPTY ;
31
33
import static org .apache .commons .lang .StringUtils .isNotBlank ;
@@ -57,14 +59,13 @@ class MappingBuilder {
57
59
static XContentBuilder buildMapping (Class clazz , String indexType , String idFieldName ) throws IOException {
58
60
XContentBuilder xContentBuilder = jsonBuilder ().startObject ().startObject (indexType ).startObject (FIELD_PROPERTIES );
59
61
60
- mapEntity (xContentBuilder , clazz , true , idFieldName , EMPTY );
62
+ mapEntity (xContentBuilder , clazz , true , idFieldName , EMPTY , new HashSet < Class >() );
61
63
62
64
return xContentBuilder .endObject ().endObject ().endObject ();
63
65
}
64
66
65
67
private static void mapEntity (XContentBuilder xContentBuilder , Class clazz , boolean isRootObject , String idFieldName ,
66
- String nestedObjectFieldName ) throws IOException {
67
-
68
+ String nestedObjectFieldName , Set <Class > ancestorClasses ) throws IOException {
68
69
java .lang .reflect .Field [] fields = clazz .getDeclaredFields ();
69
70
70
71
if (!isRootObject && isAnyPropertyAnnotatedAsField (fields )) {
@@ -78,7 +79,12 @@ private static void mapEntity(XContentBuilder xContentBuilder, Class clazz, bool
78
79
}
79
80
80
81
if (isEntity (field )) {
81
- mapEntity (xContentBuilder , field .getType (), false , EMPTY , field .getName ());
82
+ if (ancestorClasses .contains (field .getType ())) {
83
+ continue ;
84
+ } else {
85
+ ancestorClasses .add (field .getType ());
86
+ mapEntity (xContentBuilder , field .getType (), false , EMPTY , field .getName (), ancestorClasses );
87
+ }
82
88
}
83
89
84
90
Field singleField = field .getAnnotation (Field .class );
0 commit comments