OpenAPITools / OpenAPITools/openapi-generator

[REQ] Support Polymorphic Annotations for JSONB

Open
#12,343 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

According to the official communication of EF, JSONB now supports polymorphism: https://projects.eclipse.org/projects/ee4j.jsonb/releases/3.0.0

There is not much documentation about it, but I found the following example:

@JsonbTypeInfo({      
  @JsonbSubtype(alias = "dog", type = Dog.class)     
  @JsonbSubtype(alias = "cat", type = Cat.class)})
interface Animal {} 

class Dog implements Animal {    
  public String isDog = true;
}
class Cat implements Animal {   
   public String isCat = true;
}

The behaviour seems quite similar to the existing @JsonTypeInfo Annotation of Jackson. We really need this feature in order to use polymorphic DTO's with JSONB. Alternatively we could use Jackson, but unfortunately the microprofile Generator does not support it (yet).

Describe the solution you'd like

As you already implemented a type info annotation for Jackson (see https://github.com/OpenAPITools/openapi-generator/blob/60dcf8613f6b75b606757c4a991fe018ad10ee99/modules/openapi-generator/src/main/resources/kotlin-spring/typeInfoAnnotation.mustache) it would be great to have the same for JSONB.

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 with modules/openapi-generator/src/main/resources/kotlin-spring/typeInfoAnnotation.mustache, which the issue cites, and trace how that template is selected for generated Java outputs. Identify the JSONB target generators and expected annotation behavior from the example; done means generated polymorphic DTOs use JSONB type-info annotations and relevant generation tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.