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

Configuration for Include Nested Objects into JSON [DATAREST-1376] #1736

spring-projects-issues opened this issue May 13, 2019 · 3 comments


Copy link

@spring-projects-issues spring-projects-issues commented May 13, 2019

asdf fsadf opened DATAREST-1376 and commented

There could be an easy way to configure if a nested object gets presented as an url-reference or as an embedded json object.


Example to make my suggestion clear.


public class Person {

  @Id @GeneratedValue
  private Long id;
  private String firstName, lastName;

  private Address address;


Result of a standard Repository, if an repository for address exists:

  "id" : 1,
  "firstName" : "Frodo",
  "lastName" : "Baggins",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/persons/1"
    "address" : {
      "href" : "http://localhost:8080/persons/1/address"

My suggestion is to create an annotation like this:

interface PersonRepository extends CrudRepository<Person, Long> {

    // suggested new annotation
    @Embedded(fieldNames = {"address"})
    public Person findById(long id);

 To get an result like this:

    "street": "Bag End",
    "state": "The Shire",
    "country": "Middle Earth"


Issue Links:

Copy link

@spring-projects-issues spring-projects-issues commented May 13, 2019

Oliver Drotbohm commented

That's in violation with the fundamental principles that underly Spring Data REST. If you have a repository for Address, you indicate that it is a separate aggregate. I.e. accessing the item resource for your Person would return two aggregates without making this obvious. This is problematic as then an update to that very same resource would have to change two different aggregates at the same time, which requires a transaction, a concept that not all backing stores that Spring Data REST can run on supports.

There already is a concept of excerpt projections that allow you to pull parts of the representation of a related resource into the _embedded clause of the representation of a resource.

Checking the reference docs, I realized that the section on (excerpt) projections deserves a bit of a polish up so that it's easier to understand the purpose of that functionality. I filed DATAREST-1377 for that

@spring-projects-issues spring-projects-issues added status: waiting-for-feedback in: repository type: enhancement labels Dec 31, 2020
Copy link

@spring-projects-issues spring-projects-issues commented Jan 7, 2021

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder label Jan 7, 2021
Copy link

@spring-projects-issues spring-projects-issues commented Jan 14, 2021

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@spring-projects-issues spring-projects-issues removed status: waiting-for-feedback status: feedback-reminder labels Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants