Allow to customize the mapped type name for @InnerField and @Field annotations#2950
Allow to customize the mapped type name for @InnerField and @Field annotations#2950sothawo merged 2 commits intospring-projects:mainfrom
Conversation
…notations Signed-off-by: Andriy Redko <[email protected]>
| } | ||
|
|
||
| @Test | ||
| public void shouldSupportAllTypes() { |
There was a problem hiding this comment.
This one is not strictly related but EntityWithAllTypes was not used in tests at all, fixing that
|
@sothawo would really appreciate a review when you have some time, thank you |
|
tomorrow, been busy this week 😁 |
sothawo
left a comment
There was a problem hiding this comment.
Thanks for the PR, I just think that the mappedName should be called mappedTypeName so that it will not be confused with the field name, that is mapped as well from the Java property name to the Field.name attribute
| boolean storeEmptyValue() default true; | ||
|
|
||
| /** | ||
| * overrides the mapping field type which otherwise will be taken from corresponding {@link FieldType} |
There was a problem hiding this comment.
| * overrides the mapping field type which otherwise will be taken from corresponding {@link FieldType} | |
| * overrides the field type in the mapping which otherwise will be taken from corresponding {@link FieldType} |
Seems a little clearer for me
| KnnIndexOptions[] knnIndexOptions() default {}; | ||
|
|
||
| /** | ||
| * overrides the mapping field type which otherwise will be taken from corresponding {@link FieldType} |
|
|
||
| private void mapEntity(ObjectNode objectNode, @Nullable ElasticsearchPersistentEntity<?> entity, | ||
| boolean isRootObject, String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, | ||
| boolean isRootObject, String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, String mappedName, |
There was a problem hiding this comment.
| boolean isRootObject, String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, String mappedName, | |
| boolean isRootObject, String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, String fieldTypemappedName, |
might be mistaken as as mapped name of the entity
| * | ||
| * @since 5.4 | ||
| */ | ||
| String mappedName() default ""; |
There was a problem hiding this comment.
| String mappedName() default ""; | |
| String mappedTypeName() default ""; |
to not confuse with the field name
Signed-off-by: Andriy Redko <[email protected]>
Thanks a lot for the review @sothawo , comments addressed! Thanks again! |
In Spring Data OpenSearch [1], which is built on top of Spring Data Elasticsearch, we are running into cases where both projects differ in incompatible ways. One of such cases is supported mapping field types (baked by
org.springframework.data.elasticsearch.annotations.FieldType), for example:would have to become
for OpenSearch.
This pull request adds optional
mappedNameattribute to@InnerFieldand@Fieldannotations (and model classes respectively), to address the possible divergence, for example:It would require a bit more work for OpenSearch users but not the Elasticsearch ones. The change would be non-breaking (defaults to
""andFieldType::getMappedType) and work seamlessly.Closes #2942