Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

REST WS code gives error when returning ArrayList from method

 
Ranch Hand
Posts: 2561
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2561
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.








 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2561
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic