Description
Daniel Theuke opened SPR-16877 and commented
If you have a generic AbstractController that specifies a method with a @RequestMapping
and you don't overwrite it in the SpecificController then the GenericHttpMessageConverter won't get the actual data type that was returned from the method.
Due to this behavior it is impossible to use inheritance with generics for type dependent data formats such as CSV.
Provided data type: java.util.List<T>
Actual/Expected data type: java.util.List<MyDTO>
See the attached demo project for an easy way to reproduce.
There is a workaround for that though, override all the inherited methods in the SpecificController and just delegate to super.
@Override
public List<MyDTO> getList() {
return super.getList();
}
However this is easy to forget, hard to spot and just adds plenty of noise to the controllers.
I haven't made any recent tests with Spring 4.x, but IIRC that version is also affected.
Affects: 5.0.6
Attachments:
- demo.zip (3.93 kB)
Issue Links:
- Revise generic type handling in GsonHttpMessageConverter [SPR-15381] #19944 Revise generic type handling in GsonHttpMessageConverter ("duplicates")
- Enable REST controller method parameter annotations on an interface [SPR-11055] #15682 Enable REST controller method parameter annotations on an interface
Referenced from: commits b915e42