使用JAXRS时,从JSON层次结构获取对象列表

时间:2018-11-07 16:14:35

标签: java rest jax-rs

我正在创建一个API,该API将带有一个组名并为该组中的成员提供

我正在使用JAXRS从REST调用中获取响应。我的REST调用返回下面的JSON,我只对其中的Entries列表感兴趣。

如何仅从响应中提取条目并建立成员列表?

public class Member{
    private String id;
    private String displayName;
    private String memberType;

public Member(String id, String displayName, String memberType) {
    this.id = id;
    this.displayName = displayName;
    this.memberType = memberType;
}

}

/ API

public List<Member> getMembersForGroup(String groupName){
  Response response = getTarget()
                    .path("api/members/"+ groupName  )
                    .request()
                    .get();



}

我在REST调用中有一个以以下格式返回的JSON

{
    "list": {
        "pagination": {
            "count": 5,
            "hasMoreItems": false,
            "totalItems": 5,
            "skipCount": 0,
            "maxItems": 100
        },
        "entries": [
            {
                "entry": {
                    "displayName": "stanley",
                    "id": "stanley",
                    "memberType": "PERSON"
                }
            },
            {
                "entry": {
                    "displayName": "devopsteam",
                    "id": "GROUP_devopsteam",
                    "memberType": "GROUP"
                }
            },
            {
                "entry": {
                    "displayName": "admin-group",
                    "id": "admin-group",
                    "memberType": "GROUP"
                }
            },
            {
                "entry": {
                    "displayName": "Rubik",
                    "id": "rubik",
                    "memberType": "PERSON"
                }
            },
            {
                "entry": {
                    "displayName": "Craza",
                    "id": "craza",
                    "memberType": "PERSON"
                }
            }
        ]
    }
}

0 个答案:

没有答案