Friday, September 27, 2013

JAX-RS 2.0 Client API Generic Type Response Entity

Hi folks!

The last POST we learned how to use the new JAX-RS 2.0 Jersey API, you can read the introduction there. Today we will talk about the detail that was missing for reading JSON responses that uses a generic type.

The code below shows how to setup the WebTarget with the URI you want to request and then it is executed when you call the get() method. Note that this is not different from the first example.
Client orderClient = ClientBuilder.newClient();

WebTarget target ="http://localhost:8082/rest-client-api-example/resources/orders");
Response response = target
So, now we will see what really makes the difference using generics. The following line shows how a generic type should be read.

 List<order> orders = response.readEntity(new GenericType<List<Order>>() {});

It doesn't look good, but this anonymous class will do the trick. Remember that you need all the dependencies listed at my github to make this work properly.

This is it, I hope it helped!


  1. Wow! wonderful information, am amazed and i really very impressed very well articles and worth information, i can remember more days that articles.

    SEO Training in Chennai


  2. Great and useful article. Creating content regularly is very tough. Your points are motivated me to move on.

    SEO Company in Chennai

  3. Excellent post ! Thanks for sharing such a useful post.

    digital marketing training

  4. Very Nice Blog I like the way you explained these things. I’ve been looking for ways to improve my website and overall rankings.I hope your future article will help me further.Take SEO Training in Chennai to mould yourself.

  5. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
    selenium training in bangalore.

    selenium training in chennai.

  6. Great put Good stuff.All the topics were explained quickly understand for me.I am waiting for your next fantastic blog.Thanks for sharing.Any coures related details learn...

  7. Thanks for sharing the wonderful information. It's more useful and more helpful. Great work. Keep sharing.
    MCA Project Center in Chennai | MCA Project Center in Velachery

  8. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here. digital marketing training in chennai
    digital marketing training in bangalore

  9. Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!
    Best ECommerce Website developers in bangalore
    Outsource magento ecommerce services india

  10. I simply wanted to thank you so much again. I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation. digital marketing training in chennai

  11. Appreciation for really being thoughtful and also for deciding on certain marvelous guides most people really want to be aware of.

    AWS Training in Chennai


  12. Best Solidworks training institute in noida

    SolidWorks is a solid modeling computer-aided design (CAD) and computer-aided engineering (CAE) computer program that runs on Microsoft Windows. SolidWorks is published by Dassault Systems. Solid Works: well, it is purely a product to design machines. But, of course, there are other applications, like aerospace, automobile, consumer products, etc. Much user friendly than the former one, in terms of modeling, editing designs, creating mechanisms, etc.
    Solid Works is a Middle level, Main stream software with focus on Product development & this software is aimed at Small scale & Middle level Companies whose interest is to have a reasonably priced CAD system which can support their product development needs and at the same time helps them get their product market faster.

    Company Address:
    Phone No: 0120-4330760 ,+91-880-282-0025