空集合返回spring数据rest中的单个对象而不是空数组

时间:2016-11-17 12:21:38

标签: java spring rest spring-mvc spring-data-rest

我正在为我的应用程序使用spring数据休息。

我已使用以下内容禁用了hal json类型: -

 @Override
 public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {

  config.useHalAsDefaultJsonMediaType(false);
}

对于空对象,我的响应如下所示: -

{

    "links": [
        {
            "rel": "self",
            "href": "http://localhost:8081/users"
        },
        {
            "rel": "profile",
            "href": "http://localhost:8081/profile/users"
        },
        {
            "rel": "search",
            "href": "http://localhost:8081/users/search"
        }
    ],
    "content": [
        {
            "relTargetType": "com.sample.User",
            "collectionValue": true,
            "value": [ ]
        }
    ]

}

当我有用户数据时,它看起来如下: -

links": [

    {
        "rel": "self",
        "href": "http://localhost:8081/users"
    },
    {
        "rel": "profile",
        "href": "http://localhost:8081/profile/users"
    },
    {
        "rel": "search",
        "href": "http://localhost:8081/users/search"
    }

],
"content": [

    {
        "id": 2,
        "key": "wire",
        "name": "Wireless",
        "content": [ ],
        "links": [
            {
                "rel": "self",
                "href": "http://localhost:8081/users/2"
            },
            {
                "rel": "user",
                "href": "http://localhost:8081/users/2"
            }
        ]
    }..

我担心的是如下所示的空内容集: -

{

    "links": [
        {
            "rel": "self",
            "href": "http://localhost:8081/users"
        },
        {
            "rel": "profile",
            "href": "http://localhost:8081/profile/users"
        },
        {
            "rel": "search",
            "href": "http://localhost:8081/users/search"
        }
    ],
    "content": []

}

如何处理spring数据休息中的空集合?请帮助我

0 个答案:

没有答案