Examples#
Code examples below have been shortened with only relevants parts.
Basic operations#
Given a User
entity described here.
Let's say we want to expose the user name through basic CRUD_OPERATIONS
for any
context.
But we would also like to expose it for any route scope
, on a custom
operation (which is matching a custom route action with the same
operation).
And finally, we want to expose it precisely on the article context on customList operation.
Relations#
IRI#
Given a User
entity described here.
And a Role
entity described here.
Remember, since every entities should extend from the
GenericEntity interface and always have the id
property exposed, you can expose your relations IRI by just decorating
the relation with @Groups
on the parent entity.
If no other properties than id
are exposed on role for the user.details route scope
,
you will end up with a response such as :
Nested property#
To expose a nested property, you need to decorate with @Groups
both the relation (on the parent
entity) and the property (of the relation) with the same route scope
.
For this example, let's expose the user's role.title property for the details route (GET:/user/xxx
route).
That's it ! The user details route (GET:/user/1
) will contain a role object with a title property inside :
This works the exact same way with a property that is a collection
(OneToMany
/ManyToMany
)
instead of a single relation
(OneToOne
/ManyToOne
).
Still, for the sake of it let's have an example using User/Articles entities. Let's expose the user's articles.title
property for the list route (GET:/user/xxx
route).
And you would end up with this kind of response :
Of course, if you hadn't exposed the articles.title property while keeping user.articles exposed, you would only have the articles IRI returned :