Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9441
Closed
Open
Issue created May 10, 2021 by Administrator@rootContributor

[REQ] Cleanup Jackson type info mess

Created by: rpost

General question: why some java generators use JsonTypeInfo.As.EXISTING_PROPERTY and some JsonTypeInfo.As.PROPERTY?

More specific question: why spring-java generator for following specification snippet:

    Service:
      type: object
      discriminator:
        propertyName: '@type'
      required:
        - '@type'
      properties:
        '@type':
          description: JSON type discriminator, must contain object type name
          type: string
    ConcreteService:
      allOf:
        - $ref: '#/components/schemas/Service'
        - type: object

creates sources as follows:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "@type", visible = true)
@JsonSubTypes({
  @JsonSubTypes.Type(value = ConcreteService.class, name = "ConcreteService"),
})

public class Service   {
  @JsonProperty("@type")
  private String atType;

?

Why is discriminator value exposed as object property? It should be invisibile from java developer point of view. What is even worse is that I have to manually set proper type in order to have @type filled in serialized json.

Considering yaml above I would expect that

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type", visible = true)
@JsonSubTypes({
  @JsonSubTypes.Type(value = ConcreteService.class, name = "ConcreteService"),
})

public class Service   {
// no @type property!

is created.

Assignee
Assign to
Time tracking