wkennedy / swagger4spring-web

Swagger support for Spring MVC
89 stars 46 forks source link

Return type of List<T> does not display inner type #16

Closed jparish9 closed 11 years ago

jparish9 commented 11 years ago

I have a method in my api that returns a List. In the generated JSON I see this:

{
 "path":"/api/properties",
   "description":"",
   "operations":  [
      {
         "httpMethod":"GET",
         "responseClass":"List",
         "nickname":"getAllProperties"
      }
   ]
}

Since the generated responseClass is a simple List, using swagger-ui it shows as:

List {
   empty (boolean, optional)
}

It would be great if the inner type was preserved.

wkennedy commented 11 years ago

Hi jparish9,

Unfortunately, this issue has come up a few times. The problem here is do to type erasure in Java generics. From Java generics entry in Wikipedia:

"Generics are checked at compile-time for type-correctness. The generic type information is then removed in a process called type erasure. For example, List will be converted to the non-generic type List, which ordinarily contains arbitrary objects. The compile-time check guarantees that the resulting code is type-correct. As a result of type erasure, type parameters cannot be determined at run-time."