Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Associated resources gets embedded and also linked [DATAREST-1443] #1802

Closed
spring-projects-issues opened this issue Oct 23, 2019 · 6 comments
Assignees
Labels
type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Oct 23, 2019

Ľubo Varga opened DATAREST-1443 and commented

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": "nbuMaster123@test.qpp.sk"
          }
        },
        "_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)


Affects: 3.2 GA (Moore)

Reference URL: https://stackoverflow.com/questions/58213756/associated-resources-are-embedded-after-upgrading-dependency

Issue Links:

  • DATAREST-1446 DefaultExcerptProjector exposes projection present even if metadata returns Optional.empty()

Backported to: 3.2.1 (Moore SR1)

1 votes, 4 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 26, 2019

Christiaan Janssen commented

I have the exact same issue. All associations are being embedded by default after the upgrade. I tried adding the @JsonIgnore annotation to the associations, but the result is still the same. I noticed that the issue was introduced after version 2.2.0.M3. 

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 28, 2019

Ľubo Varga commented

I would bet some pullrequests that Alan Hay can bring here some light. Can you guess, in which module/class can foreigner search for problem?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 29, 2019

Thomas Schuh commented

We have the same issue. Does anyone have a workaround? JsonBackReference is not working. We get an infinite loop

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 30, 2019

Oliver Drotbohm commented

This seems to be a side-effect of the issue reported in DATAREST-1446. There was a but that caused the check for an available projection for a given type to always indicate that there's a projection available, even if it wasn't. The rendering code would then go on trying to eventually render the projection but falling back to render the entire object if no projection was in fact available.

I just tried your example on the latest snapshots (by upgrading spring-data-releasetrain.version to Moore-BUILD-SNAPSHOT and it again renders the resources as expected. Would you mind giving the snapshots a try yourself? We have a service release schedule for early next week and it would be cool if we could verify that the fix for DATAREST-1446 resolves this issue as well

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 30, 2019

Oliver Drotbohm commented

Should be fixed with the fix for DATAREST-1446

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 5, 2019

Ľubo Varga commented

Seems OK for me. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug
Projects
None yet
Development

No branches or pull requests

2 participants