I have a RESTful class which has a method which returns list of employees. I am using Jersey RESTful implementation with glassfish. I annotated my method with
and I am returning a list of employees as List<Employee>
Then I get this error
Then I created a wrapperInstead of returning List<Employee> I am returning EmployeeList. This is working fine when there are more than 1 Employee objects in the list. If there is only one Employee object in the list I get this JSONIf there are no Employee objects then I get a null. If there are more than 1 Employee objects I get this JSONThe first JSON and this JSON is different. Here I get an array where as in the first JSON I get an object.
Can anyone please tell me how to receive array in the JSON irrespective of the number of Employee objects. (For 0 Objects empty array)
Language Independent is a key word here. When you say List in Java you are talking about a Java specific collection object implementing the List interface which has methods like add(), iterator(), contains() etc etc. All things that a client of your web service does not need or understand.
It seems to me that when you are thinking "list" you are really thinking array. It is very easy to get an array out of any List with the marvelous toArray() method.
Okay I now understand why I should return an array instead of List.
But I have one question here. Even though I am returning a java List jersey converts it into json (key : value pair) and sends it right. At last the client will receive strings itself right. Then what is the problem in using List?
subject: @Produces JSON with return type List not working