[JAVA] How do I add @JsonInclude(JsonInclude.Include.NON_NULL) as part of code gen

Open
#7,696 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
tooling

Research direction

Start by reading the swagger-codegen-maven-plugin configuration around the Maven generate-sources phase and the referenced pojo.mustache template. Determine whether an environment or plugin property can control this annotation; done means generated Java POJOs include it during mvn clean generate-sources package without manual edits or a separately maintained template.

Written by the indexing model from the issue text.

Description

Description

I am using the swagger-codegen-maven-plugin to generate the models from my swagger yaml. I want to add the @JsonInclude(JsonInclude.Include.NON_NULL) annotation against each pojo that is generated and since we are using CI, we don't want to manually add this annotation after the classes (pojos) are generated. We also don't have the option of updating the pojo.mustache file either since we are using the swagger-codegen-maven-plugin plugin and not invoking the swagger-codegen jar directly.

Is there a way we can add this as a config or environment property as part of the maven generate-sources execution stage?

Swagger-codegen version

2.1.4

Swagger declaration file content or url
Command line used for generation

mvn clean generate-sources package

Steps to reproduce

Given a sample swagger yaml, try running mvn clean generate-sources package.

Related issues/PRs

https://github.com/swagger-api/swagger-codegen/issues/5309

Suggest a fix/enhancement

If we can pass this as a env property or configuration while defining my maven generate-sources, then we don't need to make any new templates - creating a new template for pojo.mustache and configuring it as part of CI may not always be a viable option.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from swagger-api/swagger-codegen

All issues in swagger-api/swagger-codegen

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.