feat: annotation support for getters #792
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe your change
This change will let you use
@JsonProperty("objectID")
annotations on custom Getter methods.To make things easier, I've dropped the custom reflection logic in favor of Jackson's internal introspection logic. This allows checking for the objectID within property names, getters and annotation values at once.
I've additionally removed the validation for objectIDs entirely for the "getObjectID" method and used an Optional fallback instead.
The tests are within an extra class to not bloat the original tests.
What problem is this fixing?
If you are working with base classes that already come with an internal ID field you want to use as the "Object ID", and you don't want to modify the base class by adding the
@JsonProperty("objectID")
annotation, you can only do that by using a custom getter in your child class.The implementation supported only scans on the field name and field annotations, not method annotations.
Additional
I've added
Not sure if it has any side effects you do not want. Stumbled accross this case within my tests and imo it won't hurt.