I am trying to doing a simple Spring app. It needs to expose REST endpoints and save it to a relational database.
I took your sample project, http://spring.io/guides
The reason for that is pretty simple: the relation names for associated entities are derived from the property names of the containing class. So both PersonDetails
and PersonChildren
want to create an outbound link to a Person
named person
. If we rendered that, it would look something like this
{ _links : {
person : { href : … }, <- the one from PersonDetails
person : { href : … } <- the one from PersonChildren
}
This is of course invalid. Also, lining up the two links in an array would not allow you to distinguish between the two links anymore (which one is coming from PersonDetails
and which one is coming from PersonChildren
.
So there are a few options here:
Person
properties with @RestResource
and configure the rel
attribute of the annotation to something different than person
.exported
flag in @RestResource
to false
and the link will not be rendered. This might be useful if the pointer e.g. from PersonDetails
is just relevant within the code, but actually not in a JSON representation.