Skip to content

How to build AnnotationOverrides from ObjectMapper #81

Open

Description

@CarstenEnglert

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?

Activity

  1. changed the title [-]How to build AnnotationOverrides from ObjectMapperr[/-] [+]How to build AnnotationOverrides from ObjectMapper[/+] on Nov 22, 2023
  2. cowtowncoder commented on Nov 27, 2023

    @cowtowncoder
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions