Uploaded image for project: 'Spring Data REST'
  1. Spring Data REST
  2. DATAREST-464

Links don't get inserted for inlined _embedded associations

    XMLWordPrintable

    Details

    • Sprint:
      56 - Fowler RC1, 56 - Fowler GA, 57 - Fowler Aftermath, 58 - Gosling M1, 59 - Evans / Fowler SR, Gosling RC1

      Description

      Let's consider authors and books relations from spring-data-rest-webmvc module tests.

      Here is an example of the authors rel output:

      {
        "_embedded": {
          "authors": [
            {
              "name": "Ollie",
              "_embedded": {
                "books": [
                  {
                    "title": "Spring Data"
                  },
                  {
                    "title": "Spring Data (Second Edition)"
                  }
                ]
              },
              "_links": {
                "self": {
                  "href": "http://localhost/authors/1"
                }
              }
            }
          ]
        }
      }
      

      Since we inlined books into authors resource we do not show the books association link in the links section for a given author. (according to DATAREST-317)

      Issue: It brakes further navigation (discoverability). It's not possible to navigate to the associated book resource from the authors collection.

      Solution: to show links for inlined resources
      Here is an example:

      {
        "_embedded": {
          "authors": [
            {
              "name": "Ollie",
              "_embedded": {
                "books": [
                  {
                    "title": "Spring Data (Second Edition)",
                    "_links": {
                      "self": {
                        "href": "http://localhost/books/2-2{?projection}",
                        "templated": true
                      },
                      "authors": {
                        "href": "http://localhost/books/2-2/authors"
                      }
                    }
                  }
                ]
              },
              "_links": {
                "self": {
                  "href": "http://localhost/authors/1"
                }
              }
            }
          ]
        }
      }
      

      This is actually how HAL suggests it to be http://stateless.co/hal_specification.html

      A pull request is underway.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              zevg Evgeniy Zakharchenko
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: