I have to pass 2 different type of objects of type apple or of type orange in RequestBody in my Spring Boot Controller method.
public myResponse myMethod(@ApiParam(value = "myRequest", required = true) @RequestBody Object mulRequest) {
In above code snippet, the mulRequest of type Object can be either of Class apple or Class orange.
I want to follow something like below logic for my requirement -
if (mulRequest instanceof apple) {
// process logic...
} else if (mulRequest instanceof orange) {
// process...
}
But I am stuck on how to cast to relevant class objects based on RequestBody passed, since I will not be knowing what type of object is getting passed for mulRequest which can be of either apple or orange class. Both apple and orange class implement the Serializable interface.
Appreciate any suggestion or ways to solve this.