typescript-generator
typescript-generator copied to clipboard
Enum converted as String if used in @JsonTypeInfo property
I have the following (simplified) data Model:
public enum ScenarioType {
SBS("SingleBrake (SBS)"),
DBS("DragBrake (DBS)"),
RPS("RouteProfile (RPS)"),
VPS("VelocityProfile (VPS)"),
TBS("TestBench (TBS)"),
PBS("ParkingBrake (PBS)"),
COMS("Commissioning (ComS)");
}
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY,
property = "scenarioType",
visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = SingleBrakeScenarioContainer.class, name = "SBS"),
@JsonSubTypes.Type(value = DragBrakingScenarioContainer.class, name = "DBS"),
})
public abstract class ScenarioDataBase {
@JsonProperty(required = true)
protected final ScenarioType scenarioType;
protected ScenarioDataBase(ScenarioType scenarioType) {
this.scenarioType = scenarioType;
}
}
public class SingleBrakeScenarioContainer extends ScenarioDataBase {
public SingleBrakeScenarioContainer() {
super(ScenarioType.SBS);
}
}
public class DragBrakingScenarioContainer extends ScenarioDataBase {
public DragBrakingScenarioContainer() {
super(ScenarioType.DBS);
}
This is converted to the following typescript model, which is not valid
export interface ScenarioDataBase {
scenarioType: string;
}
export interface SingleBrakeScenario extends ScenarioBase {
scenarioType: "SBS";
}
export interface DragBrakingScenario extends ScenarioBase {
scenarioType: "DBS";
}
export enum ScenarioType {
SBS = "SBS",
DBS = "DBS",
RPS = "RPS",
VPS = "VPS",
TBS = "TBS",
PBS = "PBS",
COMS = "COMS",
}
If I remove the TypeInfo/SubTpe Annotations, the generated File looks like this:
export interface ScenarioDataBase {
scenarioType: ScenarioType ;
}
Anything you did to come around this issue that you might share?