Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: annotation support for getters #792

Open
wants to merge 4 commits into
base: v3
Choose a base branch
from

Conversation

mklueh
Copy link

@mklueh mklueh commented Dec 17, 2023

Q A
Bug fix? no
New feature? yes
BC breaks? no
Related Issue Fix #...
Need Doc update yes/no

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

            .disable(
                SerializationFeature
                        .FAIL_ON_EMPTY_BEANS)

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.

@mklueh mklueh requested a review from aallam as a code owner December 17, 2023 20:35
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant