Search for JsonValue in all classes and interfaces#4770
Search for JsonValue in all classes and interfaces#4770ewaostrowska merged 2 commits intoswagger-api:masterfrom
Conversation
|
Thank you for your contribution! ❤️ Due to its age, we’re unable to review or merge it reliably. Thanks again for supporting the Swagger ecosystem! |
|
What? Are you serious? This is an easy change. You didn't even try to merge it, did you? |
|
Hi @T3rm1, Sorry about this. We're doing a general cleanup to avoid very old PRs staying open for so long. I assumed this PR was no longer relevant since the linked issue was already closed. If you're still waiting on this to be merged, I will reopen the PR. |
|
This fixes a bug that was introduced by the issue that was closed. I think this is still relevant. |
|
@MichakrawSB I rebased on master. Please add it to the backlog. |
0731187 to
bb08db8
Compare
|
Thank you @T3rm1 for handling this regression. This is great! I have only added few more test cases and refactored the code slightly |
This PR fixes a regression introduced by issue #3998, which added support for
@JsonValueon enum fields and private methods. That fix only searchedgetDeclaredMethods()on the enum class itself, breaking a valid Jackson pattern where@JsonValueis declared on an interface the enum implements.What was broken
When an enum implements an interface that carries
@JsonValue, swagger-core failed to find the annotation and fell back to raw enum constant names instead of the serialized values.Case 1 —
@JsonValueon an abstract interface method:Case 2 —
@JsonValueon an interface default method (overridden without repeating the annotation):What changed
ModelResolver.java— The@JsonValuemethod lookup was changed from a one-class scan:to a full hierarchy scan using the new utility:
ReflectionUtils.java— New public methodgetAnnotatedMethods(Class<?> type, Class<? extends Annotation> annotation)that walks:Object)The duplicate inner loop pattern was also refactored into a shared private helper
collectAnnotatedDeclaredMethods.@T3rm1 notes that the same gap exists for fields in inherited classes (not just methods), but intentionally defers that to a separate PR.