• Post Reply Bookmark Topic Watch Topic
  • New Topic

REST WS code gives error when returning ArrayList from method  RSS feed

 
Monica Shiralkar
Ranch Hand
Posts: 919
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am able to create a RESTful web service which returns and XML with Name and Description of User.However when I try to return an arrayList from the return value of web method instead of string I get error.


The below code for jersey web service works fine:


[/code]

On running this it does not work and gives error.Please let tell if I am doing anything wrong?

thanks
 
Monica Shiralkar
Ranch Hand
Posts: 919
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting message "A message body writer for Java class java.util.ArrayList, and Java type class java.util.ArrayList, and MIME media type application/xml was not found"

The code which generates the above error message is :





If i return a string it works fine but returning an arrayList give message "A message body writer for Java class java.util.ArrayList, and Java type class java.util.ArrayList, and MIME media type application/xml was not found"

Please tell how I can get the above code to work.

thanks.








 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try returning an array of String. There is a real simple and very fast toArray method for ArrayList.

In general web services of any flavor should not try to return Java specific object. The whole idea of a web service is to avoid being restricted to a particular language or operating system.

Bill
 
Monica Shiralkar
Ranch Hand
Posts: 919
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.

I was able to resove it. I still do not know how it got resolved because I did nothing different.Whatever i had coded.I coded again in another method and called new method instead of first it is working for new method for some strange reason.

I have one doubt.

Try returning an array of String. There is a real simple and very fast toArray method for ArrayList.


I have one doubt. I am returning Array of type Feed( Feed is my object which has feedId,feedDescription etc). This is working fine. you had mentioned returning an array of String. But how in such caSE can i return array of Strings when I need to return array of Feeds.?

Thanks.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just trying to point out that there are standard data types used by web services aimed at a wide audience.

If your service returns Java objects then only Java clients will be able to use it.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!