jsonschema2pojo icon indicating copy to clipboard operation
jsonschema2pojo copied to clipboard

Annotator#typeInfo is not called for generated Enums

Open sschulze opened this issue 3 years ago • 2 comments
trafficstars

We have to annotate all classes generated by jsonschema2pojo with a specific annotation (Quarkus @RegisterForReflection). One of our json schemas now use an enum which is generated to an inner enum-class. Sadly the Annotator#typeInfo method is not called for this generated class.

As a workaround I implemented a custom RuleFactory which only returns a subclassed EnumRule which calls the annotators after its `#createEnum()'-invocation.

If just adding the typeInfo call to the EnumRule#createEnum is a valid solution to this issue, I could happily submit it as pull request...

sschulze avatar Jun 28 '22 17:06 sschulze

I can't think of any problem this would cause. Feel free to submit a PR for this (and please include a test case). How do you attach the @RegisterForReflection annotation in typeInfo()?

joelittlejohn avatar Aug 06 '22 12:08 joelittlejohn

Sorry for my late reaction... I added the PR #1433 for this issue which is I heavily inspired by the ObjectRule. The test case is not really great, but I didn't find a similar one for ObjectRule annotators.

Regarding the @RegisterForReflection: It was rather straight forward:

public class RegisterForReflectionAnnotator extends AbstractAnnotator {
    @Override
    public void typeInfo(JDefinedClass clazz, JsonNode schema) {
        clazz.annotate(RegisterForReflection.class);
    }
}

Your question and this straight-forward approach makes me think I missed something important? :-) Regarding this annotation, the PR #1394 would make the custom implementation superfluous and I could just add the RegisterForReflection by configuration. :-)

sschulze avatar Sep 07 '22 10:09 sschulze