开发者

spring controller with deserialized list object

@RequestMapping(value = "/tester/", method = RequestMethod.POST)
    public String  testingonly(@RequestBody List<EachObject> eachobjectlist) throws IOException {

then i do iterate eachobjectlist, but each item ins开发者_运维知识库ide the list is type LinkedHashMap, arent it suppose to be "EachObject" type ?


Due to type erasure at runtime, the generic type EachObject is not present at runtime. Spring will not be able to determine this information. Spring only knows that the argument has a raw type List and it will inject a List of any type.

According to @axtavt, generic types of method's arguments are accessible but Spring may not have this implemented and probably won't be implemented in the future. This is because generic type can be interface or abstract class and Spring will not be able to create a corresponding implementation of a given interface or abstract class. For example, if you request for a list of Fruit and there are two almost identical subclasses of Fruit, dertemining which subclass to be used will not be possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜