Returned json unexpected, has “links” spelled as “_links” and structure different, in Spring hateoas

前端 未结 6 1750
情书的邮戳
情书的邮戳 2021-01-02 02:56

As the title says, I have a resource object Product extending ResourceSupport. However, the responses I receive have the property \"_links\" instea

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-02 03:00

    Spring Boot now (version=1.3.3.RELEASE) has a property that controls the output JSON format of the PagedResources.

    Just add the following config to your application.yml file:

    spring.hateoas.use-hal-as-default-json-media-type: false
    

    if you need the output to be like (based on question):

    {
      "productId" : 1,
      "name" : "2",
      "links" : [
        {
          "rel" : "self"
          "href" : "http://localhost:8080/products/1"
        }
      ]
    }
    

    Edited:

    By the way, you only need @EnableSpringDataWebSupport annotation in this way.

提交回复
热议问题