【问题标题】:How to handle that json response in java?如何在java中处理那个json响应?
【发布时间】:2016-11-11 02:19:09
【问题描述】:

我创建了一个 REST Web 服务和一个客户端。客户端正在调用一个函数来获取所有播放列表。服务正在返回一个对象列表(播放列表)。如何将此响应保存在客户端上?

资源类:

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

服务类:

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

客户端代码(我在这里遇到错误)

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

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

如何将此响应保存到播放列表列表?

【问题讨论】:

标签: java json rest web service


【解决方案1】:

我找到了解决办法。 我从:.get(List&lt;Playlist&gt;.class); 至:.get(new GenericType&lt;List&lt;Playlist&gt;&gt;() {});

我在 youtube 上找到了修复方法:https://www.youtube.com/watch?v=fxDFpVLUDFY&list=PLqq-6Pq4lTTY40IcG584ynNqibMc1heIa&index=19

【讨论】:

    猜你喜欢
    • 2017-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    • 2011-08-10
    相关资源
    最近更新 更多