DATAES-784 - MappingBuilder should use @Field annotation with custom value objects.

Original PR: #423
This commit is contained in:
Peter-Josef Meisch 2020-04-07 14:40:41 +02:00 committed by GitHub
parent 3afd6fd427
commit bbc9ec213a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 16 deletions

View File

@ -197,37 +197,35 @@ public class MappingBuilder {
}
}
boolean isGeoPointProperty = isGeoPointProperty(property);
if (isGeoPointProperty(property)) {
applyGeoPointFieldMapping(builder, property);
return;
}
Field fieldAnnotation = property.findAnnotation(Field.class);
boolean isCompletionProperty = isCompletionProperty(property);
boolean isNestedOrObjectProperty = isNestedOrObjectProperty(property);
Field fieldAnnotation = property.findAnnotation(Field.class);
if (!isGeoPointProperty && !isCompletionProperty && property.isEntity() && hasRelevantAnnotation(property)) {
if (!isCompletionProperty && property.isEntity() && hasRelevantAnnotation(property)) {
if (fieldAnnotation == null) {
return;
}
Iterator<? extends TypeInformation<?>> iterator = property.getPersistentEntityTypes().iterator();
ElasticsearchPersistentEntity<?> persistentEntity = iterator.hasNext()
? elasticsearchConverter.getMappingContext().getPersistentEntity(iterator.next())
: null;
mapEntity(builder, persistentEntity, false, property.getFieldName(), isNestedOrObjectProperty,
fieldAnnotation.type(), fieldAnnotation, property.findAnnotation(DynamicMapping.class));
if (isNestedOrObjectProperty) {
Iterator<? extends TypeInformation<?>> iterator = property.getPersistentEntityTypes().iterator();
ElasticsearchPersistentEntity<?> persistentEntity = iterator.hasNext()
? elasticsearchConverter.getMappingContext().getPersistentEntity(iterator.next())
: null;
mapEntity(builder, persistentEntity, false, property.getFieldName(), isNestedOrObjectProperty,
fieldAnnotation.type(), fieldAnnotation, property.findAnnotation(DynamicMapping.class));
return;
}
}
MultiField multiField = property.findAnnotation(MultiField.class);
if (isGeoPointProperty) {
applyGeoPointFieldMapping(builder, property);
return;
}
if (isCompletionProperty) {
CompletionField completionField = property.findAnnotation(CompletionField.class);
applyCompletionFieldMapping(builder, property, completionField);

View File

@ -545,6 +545,21 @@ public class MappingBuilderTests extends MappingContextBaseTests {
assertEquals(expected, mapping, true);
}
@Test // DATAES-784
void shouldMapPropertyObjectsToFieldDefinition() throws JSONException {
String expected = "{\n" + //
" properties: {\n" + //
" valueObject: {\n" + //
" type: \"text\"\n" + //
" }\n" + //
" }\n" + //
"}";
String mapping = getMappingBuilder().buildPropertyMapping(ValueDoc.class);
assertEquals(expected, mapping, true);
}
/**
* @author Xiao Yu
*/
@ -997,4 +1012,21 @@ public class MappingBuilderTests extends MappingContextBaseTests {
this.author = author;
}
}
static class ValueObject {
private String value;
public ValueObject(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
@Document(indexName = "valueDoc")
static class ValueDoc {
@Field(type = Text) private ValueObject valueObject;
}
}