swagger-api / swagger-api/swagger-codegen

[JAVA] JAXB models should not have to include JSON-related annotations

Open
#6,054 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Java Enhancement: General
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I am testing the recently improved support for generating JAXB-based models (#5962 and #6005).
The generated code always includes JSON-related annotations, which are unnecessary for a XML-based API.

Swagger-codegen version

2.2.3-SNAPSHOT

Configuration file
{
  "sourceFolder" : "src/main/java",
  "withXml": true,
  "modelPackage" : "my.model.package",
  "additionalProperties" : { 
    "gson": false 
  }
}
Command line used for generation
    java -Dmodels -jar swagger-codegen-cli.jar \
        generate -i swagger.json  -l java -c config.json
Steps to reproduce

Run the generator using the provided configuration file and any Swagger spec. Observe the generated model classes end up with references to annotations and types from com.google.gson. It is fine if that is the default, but it should not be mandatory.

Related issues
Suggest a Fix

I can change my configuration using the library option to choose a different JSON library. Maybe I should be able to specify "none"?

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.

Research direction

Start by running the Java generator with the provided config.json and swagger.json, then inspect the generated model classes for com.google.gson references. Trace the Java model generation entry point and templates involved in JAXB output; done means XML-only generation no longer requires JSON annotations or Gson types when gson is false.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.