Skip to content
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

How to build AnnotationOverrides from ObjectMapper #81

Open
CarstenWickner opened this issue Nov 22, 2023 · 1 comment
Open

How to build AnnotationOverrides from ObjectMapper #81

CarstenWickner opened this issue Nov 22, 2023 · 1 comment

Comments

@CarstenWickner
Copy link

Hi Tatu,

In the context of my JSON Schema Generator library, I've been asked to support the mix-ins registered on a given Jackson ObjectMapper, when resolving members via classmate.
I saw the usage of the AnnotationOverrides type in classmate expecting this method to be implemented:

List<Class<?>> mixInsFor(ClassKey);

Unfortunately, the ClassKey is a utility type, which doesn't offer a getter for the wrapped Class, which complicates things.

Likewise on the Jackson ObjectMapper, there is no way to retrieve a full set of registered mix-ins as a simple Map. Just this method:

Class<?> findMixInClassFor(Class<?>)

Any suggestions on how to implement the AnnotationOverrides based on a fully configured ObjectMapper without requiring the same mix-ins to be provided all over again?

@CarstenWickner CarstenWickner changed the title How to build AnnotationOverrides from ObjectMapperr How to build AnnotationOverrides from ObjectMapper Nov 22, 2023
@cowtowncoder
Copy link
Member

@CarstenWickner I am not sure I have a good answer at this point; some access does seem to be missing.

On possible changes: addition of accessor for raw class for ClassKey would be perfectly acceptable -- both for ClassMate and Jackson. From practical perspective it's probably quicker to get a version of ClassMate released with such change due to much longer release cycle of Jackson.

But the real challenge is the ability (or lack thereof) to find all mix-ins registered: Jackson's MixInResolver leaves out bulk accessor on purpose: this allows resolver to dynamically figure things out, so that definition is not necessarily simple mapping from Class to Class... although the default implementation does implement it that way.

I guess one possibility would be to add optional accessor for this information; where implementations would be free to throw UnsupportedOperationException is implementation does not (can not) provide such mapping.
Mapping itself should be provided as a callback of some sort, not returning Map but allowing iteration over entries.
I would accept a PR for doing that.

But also... I am not sure if MixInResolver itself is yet accessible: if not, getter for that would be acceptable addition as well.

All of which is to say that quite a bit of work would be needed so I don't have a quick solution. But would be happy to work in providing some access if you have time to contribute.

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

No branches or pull requests

2 participants