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

Associated resources gets embedded and also linked

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.2 GA (Moore)
    • Component/s: None
    • Labels:
      None

      Description

      There is some regression between spring parent release 2.1.5 and 2.2.0. For example, have a look at https://github.com/luvarqpp/poc-springHalRelations/tree/solution/extendedAccordingDannyLesnikAnswer repository (note referenced branch and please ignore that given repo was created for another stackoverflow question; thus ignore its readme).

       

      When you request http://localhost:8080/api/publishers url, you will get this:

      with 2.1.5.RELEASE:

      {
        "_embedded": {
          "publishers": [
            {
              "name": "Publisher A",
              "_links": {
                "self": {
                  "href": "http://localhost:8080/api/publishers/1"
                },
                "publisher": {
                  "href": "http://localhost:8080/api/publishers/1"
                },
                "friends": {
                  "href": "http://localhost:8080/api/publishers/1/friends"
                },
                "createdBy": {
                  "href": "http://localhost:8080/api/publishers/1/contact"
                }
              }
            }
          ]
        },
        "_links": {
          "self": {
            "href": "http://localhost:8080/api/publishers{?page,size,sort}",
            "templated": true
          },
          "profile": {
            "href": "http://localhost:8080/api/profile/publishers"
          }
        },
        "page": {
          "size": 20,
          "totalElements": 1,
          "totalPages": 1,
          "number": 0
        }
      }
      

      with 2.2.0.RELEASE:

      {
        "_embedded": {
          "publishers": [
            {
              "name": "Publisher A",
              "_embedded": {
                "createdBy": {
                  "loginName": "Master123",
                  "email": "[email protected]"
                }
              },
              "_links": {
                "self": {
                  "href": "http://localhost:8080/api/publishers/1"
                },
                "publisher": {
                  "href": "http://localhost:8080/api/publishers/1"
                },
                "friends": {
                  "href": "http://localhost:8080/api/publishers/1/friends"
                },
                "createdBy": {
                  "href": "http://localhost:8080/api/publishers/1/contact"
                }
              }
            }
          ]
        },
        "_links": {
          "self": {
            "href": "http://localhost:8080/api/publishers{?page,size,sort}",
            "templated": true
          },
          "profile": {
            "href": "http://localhost:8080/api/profile/publishers"
          }
        },
        "page": {
          "size": 20,
          "totalElements": 1,
          "totalPages": 1,
          "number": 0
        }
      }
      

      I would expect that "createdBy" (ManyToOne mapping) relation will be as link only, or as embedded thing (projection?) only.

      Sidenote: "author" is preferred over "createdBy" according iana registry. Are there any way how to detect/check for errors like this one? Some commonly used synonyms which have standardized equivalent?

       

      PS: If you point me in some direction, I can try to make pull-request with fix. This problem bothers me a lot due failing tests (restdocs).

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              luvarqpp Ľubo Varga
              Last updater:
              Spring Issues Spring Issues
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: