Skip to content

Feature/inherited json identity info #946

New issue

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

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

Already on GitHub? Sign in to your account

Conversation

kschaefe
Copy link
Contributor

@kschaefe kschaefe commented Feb 5, 2023

Jackson serializes subclasses of classes annotated with JsonIdentityInfo as if the class itself were annotated with JsonIdentityInfo. See the updates to ObjectAsIdTest.testJackson to prove this is the case. The TypeScript generator was not producing correct interface definitions because it was not properly recognizing all JsonIdentityInfo cases. JsonIdentityInfo isn't Inherited, even if it were Class.getAnnotation doesn't return inherited annotations. We need to manually walk the target class upward looking for JsonIdentityInfo.

This PR adds an example of this problem to the test cases. First making the test cases pass with the current behavior. Next making the test cases fail using the expected behavior. Finally updating Jackson2Parser to make the tests pass.

I simply added a utility method in Jackson2Parser to support this change. I see you have some utilities classes, but was unsure of your style for that. The method should be easy to move wherever you feel is best. Thanks.

Represent the current (buggy) state in the unit test.

Note: that Jackson treats the subclass as a `JsonIdentityInfo` even
though the annotation is not inherited.
Subclasses of `JsonIdentityInfo` class should be treated like
`JsonIdentityInfo` classes.
The parser needs to walk the class hierarchy looking for
`JsonIdentityInfo` because the annotation is not marked as `Inherited`,
but Jackson observes the `JsonIdentityInfo` behavior on subclasses
regardless.
@vojtechhabarta vojtechhabarta merged commit b72681d into vojtechhabarta:main Mar 19, 2023
@vojtechhabarta
Copy link
Owner

Thanks for your PR.
I think this annotation propagates not only from superclasses but also from interfaces. For that there is getAnnotationRecursive method, so I used it. Let me know if that's not correct.

@vojtechhabarta
Copy link
Owner

Released in 3.2.1263.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants