Skip to content

[Java] Generator produces a dedicated field for the discriminator #8137

@marcelstoer

Description

@marcelstoer

Origin: https://stackoverflow.com/q/50163882/131929

Is it correct that the generator produces a dedicated field for the discriminator?

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "errorType", visible = true)
@JsonSubTypes({
    @JsonSubTypes.Type(value = SpecificError.class, name = "SpecificError"),
})
public class GeneralError {
    @JsonProperty("errorType")
    private String errorType = null;
    ...

errorType is the declared discriminator.

When Jackson serializes a SpecificError object it includes errorType twice:

{"errorType":"SpecificError","message":"message","errorType":null}

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