Skip to content

Bug: Custom serialization/deserialization using Jackson ObjectMapper is impossible due to ignoring discrimination type getter #22527

@dnowo

Description

@dnowo

I think that it should be removed, more details here: #12777

Best solution for fix is to conditionally remove JsonIgnoreProperties annotation which currently is generating likeso:

  @JsonPropertyOrder({
      AbstractRule.JSON_PROPERTY_RULE_TYPE,
      AbstractRule.JSON_PROPERTY_SEVERITY
    })
    @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")



    @JsonIgnoreProperties(
      value = "type", // ignore manually set type, it will be automatically generated by Jackson during serialization
      allowSetters = true // allows the type to be set during deserialization
    )


    @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
    @JsonSubTypes({
      @JsonSubTypes.Type(value = EntityVerificationRule.class, name = "impl_1"), // <-- this needs to go first as this is what is defined in the source model
      @JsonSubTypes.Type(value = HostAvailabilityRule.class, name = "impl_2"),  // <-- this needs to go first as this is what is defined in the source model
      @JsonSubTypes.Type(value = EntityVerificationRule.class, name = "Impl1"),
      @JsonSubTypes.Type(value = HostAvailabilityRule.class, name = "Impl2")
    })
    public class Base {
      // ...
    }
    
  • Allow disable / configure the code generation of:
    @JsonIgnoreProperties(
      value = "{{{discriminator.propertyBaseName}}}", // ignore manually set {{{discriminator.propertyBaseName}}}, it will be automatically generated by Jackson during serialization
      allowSetters = true // allows the {{{discriminator.propertyBaseName}}} to be set during deserialization
    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions