Bianca
Bianca

Reputation: 829

Abstract class as parameters in Spring method

I have an abstract class named "AbstractDTO". My purpose is to have a method adnotated with RequestMapping "/info", which receives as a parameter an AbstractDTO, but recognizes in the method the concrete class of the object sent as a parameter, something like "FirstDTO". How can I do that?

Upvotes: 2

Views: 737

Answers (1)

Jesper
Jesper

Reputation: 206816

I haven't tried it out, but to make this work you should create a RequestMappingHandlerAdapter bean on which you can set a custom argument resolver.

That argument resolver implements interface HandlerMethodArgumentResolver and takes care of converting what's received via HTTP to an instance of the relevant subclass of AbstractDTO.

For more details see Defining @RequestMapping handler methods in the Spring Framework reference documentation, and the API docs that I linked to above.

Upvotes: 1

Related Questions