为什么REST API响应包含bean名称?

时间:2015-04-06 23:27:29

标签: java json api rest response

我需要一个像:

这样的回复
[
    {
        "id": 1,
        "site": "Google",
        "name": "abc",
        "value": "111",
        "level": "BASE",
        "character": "&"
    },
    {
        "id": 2,
        "site": "Yahoo",
        "name": "xyz",
        "value": "222",
        "level": "ONE",
        "character": ";"
    }
]

相反,这是我得到的回应:

{
    "responseObjects": [
        [
            {
                "id": 1,
                "site": "Google",
                "name": "abc",
                "value": "111",
                "level": "BASE",
                "character": "&"
            },
            {
                "id": 2,
                "site": "Yahoo",
                "name": "xyz",
                "value": "222",
                "level": "ONE",
                "character": ";"
            }
        ]
    ]
}

我的Response类有以下成员:

private final List<Object> responseObjects = new ArrayList<Object>();

public List<Object> getResponseObjects() {
    return responseObjects;
}

public void addToResponseObjects(Object responseObject) {
    responseObjects.add(responseObject);
}

在我的Resource类中,我有这个返回响应的代码:

List<MyBean> responseList = new ArrayList<MyBean>();
.....
.....
.....
response.addToResponseObjects(responseList);
return response;

在响应中添加“responseObjects”需要做哪些更改?我只需要在响应中拥有JSON字符串/数组。

0 个答案:

没有答案