• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Use of jersey and javax.ws.rs.core.Response

 
Ranch Hand
Posts: 209
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm experimenting with some minor variations to the Maven jersey-quickstart-webapp.

I have a trivial Person class

and a resource that returns a json representation of a List<Person>

So far, this works as expected.
However, I'm wanting to return a custom http header in response to the GET and although I've not added that custom header yet, I read that I can do so if I use a Response object.
I was expecting this code,  to return the same json

However attempting to GET this resource results in a 500 Internal Server Error. The Tomcat error log says:

Could anyone point out my error here?
I was expecting that whatever classes are needed to translate a List<Person> into json, and are evidently available in the first implementation of MyResource, would also work in the second.
 
Ranch Hand
Posts: 62
5
Eclipse IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richard Hayward wrote:
Could anyone point out my error here?


You need javax.ws.rs.core.GenericEntity. Please, see the official javadoc or here (end of page).

If you don't know these aspects of generics, it may seem a bit weird at first ... yes, you need a subclass (an anonymous class in that case) in order to have a full representation at runtime of a List<Something>. ;)
 
Richard Hayward
Ranch Hand
Posts: 209
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Andrea, problem solved! The book you linked to looks useful as well.

I've been trying various things over the last couple of days, but none of them worked. It does seem odd syntax.

 
Hang a left on main. Then read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic