In my Spring boot service, I have a controller as below
@PostMapping
public ApiResponse generateUKLabel(@RequestBody LabelRequestData data){
//do operation
}
Here, LabelRequestData has List of base class. In, request I am passing child class data with base class data. But, Child class data seems to be ignored.
Is there any way I can access the child class data. I want to make the LabelRequestData with Base class generic so that it can accept multiple child class data.
Is there any way to solve it?
I tried casting. but throws can't cast exception I also tried generics. but then I need to create two controller method to handle those request. I want only one controller method to handle the request
@Data
public class LabelRequestData extends BaseRequestData {
@Valid
private List<BaseClass> labelData; // this base class has multiple child classes that i need
@Valid
private PreferenceData preferenceData;
}