-
Notifications
You must be signed in to change notification settings - Fork 563
Description
Spring Data Rest creates links in a resource for all its associations which types have an exported REST repository, otherwise they are inlined as their configured JSON representation.
The created links are represented in terms of the containing resource though so the same referenced resource could have mutliple identifiers, which is not cache friendly.
For example given the following entities:
@Entity
public class Person {
@Id
private Long id;
private String name;
private String surname;
private int age;
@OneToOne(cascade = ALL)
private Address address;
...
}
@Entity
public class Address {
@Id
private Long id;
private String address;
private Sting zip;
...
}If both entities have an exported REST repository, a JSON representation would look something like:
{
"name" : "name",
"surname" : "surname",
"age" : 11,
"_links" : {
"self" : {
"href" : "http://localhost/people/1"
},
"person" : {
"href" : "http://localhost/people/1"
},
"address" : {
"href" : "http://localhost/people/1/address"
}
}
}If the related address has id=2, for example, then the same instance can be addressed as both:
http://localhost/people/1/address
and
http://localhost/addresses/2
We believe that a more cache friendly representation would be as:
{
"name" : "name",
"surname" : "surname",
"age" : 11,
"_links" : {
"self" : {
"href" : "http://localhost/people/1"
},
"person" : {
"href" : "http://localhost/people/1"
},
"address" : {
"href" : "http://localhost/addresses/2"
}
}
}Expanding on that, if the Person entity had an association to a collection of Addresses, we also believe that links to that collection could be more cache friendly if represented as:
{
"name" : "name",
"surname" : "surname",
"age" : 11,
"_links" : {
"self" : {
"href" : "http://localhost/people/1"
},
"person" : {
"href" : "http://localhost/people/1"
},
"addresses" : [{
"href" : "http://localhost/addresses/1"
},{
"href" : "http://localhost/addresses/2"
}]
}
}We use that representation in our application and we were able to do that by overriding the LinkCollector bean.
Recently though, as reported in #1981, RepositoryRestMvcConfiguration can no longer be subclassed, so we would like to either restore the previous support, or add the ability to obtain the desired behaviour.