Description
I just noticed that if we set a custom name for a scripted field, it won't be mapped correctly to the entity in question while reading it.
Example:
@Document("my-test")
class ScriptFieldProperty {
...
@ScriptedField(name = "scripted-field-property")
String scriptedFieldProperty;
}
I did some investigation and noticed that when we moved the populateScriptFields
method from using ReflectionUtils
to PersitenceEntity
on 9d57410, this condition:
if (property.isAnnotationPresent(ScriptedField.class) && fields.containsKey(property.getName())) {
will never be true for custom names,since property#getNames
is unaware of the ScriptedField
annotation. In the previous example, it will always return scriptedFieldProperty
instead of the expected scripted-field-property
I can see two ways of solving the issue.
- Remove the second part of the conditional and do the check internally. The name should come first from the annotation and only fall back to the property if it is not set. (Note this is already done before setting the value)
- Make
SimpleElasticsearchPersistentProperty
aware of the ScriptedField annotation. By adding a condition to check it inSimpleElasticsearchPersistentProperty#getAnnotatedFieldName
, we can also ensure that the property has the correct name when populating the scripted fields.
I'm unsure of any other valid solution and would love some input. I have both solutions implemented locally and can create a PR if needed
Update: created a PR with the changes here #3023