【问题标题】:Chage in spring data rest output format in spring-data-rest-webmvc version 2.2.1.RELEASEspring-data-rest-webmvc 版本 2.2.1.RELEASE 中 spring data rest 输出格式的变化
【发布时间】:2015-01-01 15:12:12
【问题描述】:

我正在使用 spring data rest web mvc 2.2.1.RELEASE。 我期待以下格式

{
    "content": [ {
        "price": 499.00,
        "description": "Apple tablet device",
        "name": "iPad",
        "links": [ {
            "rel": "self",
            "href": "http://localhost:8080/product/1"
        } ],
        "attributes": {
            "connector": "socket"
        }
    }, {
        "price": 49.00,
        "description": "Dock for iPhone/iPad",
        "name": "Dock",
        "links": [ {
            "rel": "self",
            "href": "http://localhost:8080/product/3"
        } ],
        "attributes": {
            "connector": "plug"
        }
    } ],
    "links": [ {
        "rel": "product.search",
        "href": "http://localhost:8080/product/search"
    } ]
}   

但我得到这样的输出:

    {
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/people{?page,size,sort}",
      "templated" : true
    },
    "search" : {
      "href" : "http://localhost:8080/people/search"
    }
  },
  "_embedded" : {
    "people" : [ {
      "firstName" : "Frodo",
      "lastName" : "Baggins",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/people/1"
        }
      }
    }, {
      "firstName" : "Frodo",
      "lastName" : "shukla",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/people/2"
        }
      }
    } ]
  },
  "page" : {
    "size" : 20,
    "totalElements" : 2,
    "totalPages" : 1,
    "number" : 0
  }
    }

为什么我用 _embedded 代替内容 _links 代替链接

而 rel 属性缺失..

我正在尝试将 json 反序列化回 hatos 资源,但由于格式更改,我无法做到这一点。

提前感谢您的帮助

【问题讨论】:

    标签: rest spring-data-rest hateoas spring-hateoas


    【解决方案1】:

    SDR 2.X 以HAL 格式输出内容,因此输出_links 和_embedded。详情请参阅HAL 规范

    【讨论】:

    • 很好,我根据 HAL 规范调整了我的 jpa 客户端
    【解决方案2】:

    您期望的结果是 spring-data-rest 1.x 产生的结果。 2.x 中的默认格式是HAL。但是应该可以通过更改此错误解决方案中所述的默认媒体格式来回退到旧格式:https://jira.spring.io/browse/DATAREST-213。

    【讨论】:

      【解决方案3】:

      我根据 HAL 规范调整了我的 JPA Rest Client/

      【讨论】:

        猜你喜欢
        • 2016-10-26
        • 1970-01-01
        • 1970-01-01
        • 2016-08-16
        • 2015-12-31
        • 1970-01-01
        • 2014-07-08
        • 1970-01-01
        • 2015-05-04
        相关资源
        最近更新 更多