mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-31 09:12:11 +00:00
DATAES-784 - MappingBuilder should use @Field annotation with custom value objects.
Original PR: #423
This commit is contained in:
parent
3afd6fd427
commit
bbc9ec213a
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user