I am writing an custom annotator in jsonschema2pojo in order to tweak how this code generator annotates generated class with Jackson annotations.
To simplify the usecase, I have a JClass at hand that is already annotation with
JsonInclude( JsonInclude.Include.NON_NULL )
and I want to replace it with:
JsonInclude( JsonInclude.Include.NON_EMPTY )
I am using com.sun.codemodel:codemodel:2.6
If I attempt to add the annotation without removing the original one
JDefinedClass clazz = ...; // the class we want to annotate
clazz.annotate(JsonInclude.class).param( "value", JsonInclude.Include.NON_EMPTY );
Then I get a compile error saying that I cannot have mode than one @JsonInclude.
So I tried to remove the annotation prior to adding it
JCodeModel codeModel = new JCodeModel();
JClass jsonInclude = codeModel.ref(JsonInclude.class);
clazz.annotations().remove( jsonInclude );
but the collection of annotations is unmodifiable...
Is there a way to remove a specific annotation from a JDefinedClass ?