Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
Ranch Hand
Posts: 205
13
Notepad
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 205
13
Notepad
  • Mark post as helpful
  • send pies
  • 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.

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