-1

I have created a rest web service and a client. Client is calling a function to get all playlists. Service is returning a List of objects(Playlist). How to save this response on a client?

Resource class:

@GET
public List<Playlist> getAllPlaylists(){
    return playlistservice.getAllPlaylists();
}

Service class:

    public List<Playlist> getAllPlaylists(){
    return new ArrayList<Playlist>(playlists.values());
}

Client code(im getting error here)

List<Playlist> a = new ArrayList<Playlist>();

                        a = playlistsTarget
                                .request()
                                .get(List<Playlist>.class); // error here

How to save this response to List of playlist?

beli
  • 57
  • 1
  • 7
  • Please show understandable client code with a bit more context – Scary Wombat Nov 11 '16 at 02:24
  • Possible duplicate of [JSON generic collection deserialization](http://stackoverflow.com/questions/39273998/json-generic-collection-deserialization) – Jezor Nov 11 '16 at 02:28

1 Answers1

0

I have found the fix. I changed from: .get(List<Playlist>.class); to: .get(new GenericType<List<Playlist>>() {});

I found the fix on youtube here: https://www.youtube.com/watch?v=fxDFpVLUDFY&list=PLqq-6Pq4lTTY40IcG584ynNqibMc1heIa&index=19

beli
  • 57
  • 1
  • 7