I am using Lombok annotations in every class and the code is as follows :
public class DtoClass {
private Vehicle metadata;
}
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY. property="type")
@JsonSubTypes({@JsonSubTypes.Type(value=Car.class, name="car"),{@JsonSubTypes.Type(value=Bike.class, name="bike")}})
public class Vehicle {
//this acts as an abstraction class
}
@JsonTypeName("car")
public class Car extends Vehicle{
@NotNull
private String carLicensePlate;
@NotNull
private String carModel;
}
@JsonTypeName("bike")
public class Bike extends Vehicle{
@NotNull
private String bikeLicensePlate;
}
How can I access the value of the variable carModel
in this case? If I use DtoClass.getMetadata()
it will return the value of all the variables depending upon if its a Car or Bike, for example:
{
"type" : "car",
"carLicensePlate" : "ABCDC",
"carModel" : "Tesla"
}
but I only need the value of the variable carModel
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…