Skip to content

fix: duplicated discriminator serialisation issue [Work In progress]#1220

Open
YuriiBatkovych wants to merge 1 commit intomainfrom
fix/dublicated-discriminator-issue
Open

fix: duplicated discriminator serialisation issue [Work In progress]#1220
YuriiBatkovych wants to merge 1 commit intomainfrom
fix/dublicated-discriminator-issue

Conversation

@YuriiBatkovych
Copy link
Collaborator

This PR addresses OpenAPI-Generator Issue #3796, where the discriminator property is serialized twice in Java Jackson projects.

The Problem

When using a discriminator with Jackson, the generator currently includes allowGetters = true within the @JsonIgnoreProperties annotation. This configuration inadvertently tells Jackson that even though the property is "ignored," it is still allowed to be accessed via its getter during the serialization process.

Because @JsonTypeInfo is also configured to include the discriminator (via visible = true and include = JsonTypeInfo.As.PROPERTY), Jackson ends up writing the field twice:

  • Once from the explicit class property/getter.
  • Once from the internal Jackson polymorphic handling.

The Fix

We have modified typeInfoAnnotation.mustache to remove allowGetters = true.

  • Removal of allowGetters = true: This ensures that Jackson ignores the manual getter during serialization, preventing the duplicate field.

  • Retention of allowSetters = true: This remains necessary to ensure that the discriminator can still be mapped to the class field during deserialization.

@YuriiBatkovych YuriiBatkovych changed the title fix: duplicated discriminator serialisation issue fix: duplicated discriminator serialisation issue [Work In progress] Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant