joelittlejohn / jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
http://www.jsonschema2pojo.org
Apache License 2.0
6.24k stars 1.66k forks source link

Annotator#typeInfo is not called for generated Enums #1413

Open sschulze opened 2 years ago

sschulze commented 2 years ago

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...

joelittlejohn commented 2 years ago

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()?

sschulze commented 2 years ago

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. :-)