So, I have a VehicleDto:
class VehicleDto {
private String someId
private String vType;
private CarDto car;
private BikeDto bike;
}
I need to have either the CarDto or BikeDto in the request payload.
In the post request payload there will be multiple fields which are properties of VehicleDto, for example, here someId. Now, this someId is also a part of CarDto and BikeDto, and any other Dto that is a child of VehicleDto.
So when I try to save into the db, I have some issues there.
if (vehicleDto.getVType().equals("CAR")) {
this.saveCar(vehicleDto);
}
private boolean saveCar(TicketSoldCreateDto ticketSoldCreateDto) {
CarDto carDto = ticketSoldCreateDto.getCar();
carDto is mapped to Car model
// Now how do I map the rest of the fields in vehicleDto to Car model??
}
Super class Vehicle:
@MappedSuperclass
@Data
public abstract class Vehicle extends AbstractBaseEntity {
// fields same as vehicleDto
}
Child class Car:
@Entity
@Data
public class Car extends Vehicle {
// Some fields
}
How should I design such problems?