Please see attached code, Seems that type is incorrectly resolved for controller method's RequestBody argument. In case we have one level of inheritance, type resolved correctly. In case we have two or more levels of inheritance, type resolved incorrectly.

For example, in scenario in which type gets resolved correctly in all cases, I would expect to get the string "ConcreteType" as a result for triggering all following apis: * https://localhost:.../working/type1 * https://localhost:.../working/type2 * https://localhost:.../not_working/type1 * https://localhost:.../not_working/type2

However, 'working' path yields the correct result - "ConcreteType", while 'not_working' path yields the wrong result - "AbstractType".

dependencies: spring-boot-starter:2.6.1 spring-boot-starter-web:2.6.1 spring-boot-starter-undertow:2.6.1 spring-web:5.3.13

public class AbstractType
{
    private String id;

    public String getId()
    {
        return id;
    }
}
public class ConcreteType extends AbstractType
{
    private String name;

    public String getName()
    {
        return name;
    }
}
@RestController
@RequestMapping(value = "/not_working", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public class NotWorkingConcreteAPI extends SingleParameterizedGenericAPI<ConcreteType>
{
}
@RestController
@RequestMapping(value = "/working", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public class WorkingConcreteAPI extends MultiParameterizedGenericAPI<ConcreteType, ConcreteType>
{
}
public abstract class SingleParameterizedGenericAPI<T extends AbstractType> extends MultiParameterizedGenericAPI<T, T>
{
}
public class MultiParameterizedGenericAPI<TYPE_1 extends AbstractType, TYPE_2 extends AbstractType>
{
    @PostMapping("/type1")
    public String type1(@RequestBody TYPE_1 t1)
    {
        return t1.getClass().getSimpleName();
    }

    @PostMapping("/type2")
    public String type2(@RequestBody TYPE_2 t2)
    {
        return t2.getClass().getSimpleName();
    }
}

Comment From: poutsma

I think this might be due to Java's runtime type erasure, and not Spring. Could you please provide us with a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the issue?

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.