jsonschema2pojo icon indicating copy to clipboard operation
jsonschema2pojo copied to clipboard

Property to provide a list of @SuppressWarnings values

Open mattbishop opened this issue 4 years ago • 4 comments

We have pretty strict maven POMs that include PMD and checkstyle. I am struggling to get those code checkers to play well with generated code (don't tell me to use /target/generated* please!).

Can we have a feature that will drop in A @SuppressWarnings annotation in the generated code? Something like:

<suppressWarnings>PMD,checkstyle</suppressWarnings>

mattbishop avatar Apr 30 '21 22:04 mattbishop

You can use custom annotator

eirnym avatar May 01 '21 07:05 eirnym

@mattbishop Are you using the latest version of jsonschema2pojo?

We have reinstated the @Generated annotation, and most static code analysis tools will ignore types that have this annotation.

If this doesn't help, I think it should be quite easy to write a custom annotator for this, as @eirnym mentioned. If you can share your code to GitHub I expect others might find it useful.

joelittlejohn avatar May 01 '21 11:05 joelittlejohn

When I looked into PMD and @Generated, their philosophy is to fix the generator to pass the project's PMD rules! In my situation, this is a large, crufty Enterprise App where I don't have control over the code-checking rules, because their QA folks really want these rules to be followed. Fair enough.

I'm not sure how to get my own @SuppressWarnings handler into the plugin's class path without creating a new module to produce it? See "Enterprise App" above for my restrictions.

Another way to do this is to comment out the plugin in Maven after generation and add the @SuppressWarnings manually. Not great round-tripping, but it's what I am doing now.

mattbishop avatar May 01 '21 17:05 mattbishop

It's common to keep generated sources and files that are under source control separately. In fact it's rare to generate files into a source directory that you are including in PMD runs.

Yes you would have to add a new annotator as a module. So this option is off the table too?

Is there anything that PMD is highlighting that you think we should change in the generated sources?

joelittlejohn avatar May 01 '21 18:05 joelittlejohn