I'm using Spring Data REST 2.1.4.RELEASE.
I created
- an entity
Booking, - its REST repository (extending
CrudRepository) namedBookingRepository - and a projection
BookingDetails(annotated with@Projection(name="details", types = Booking.class)) for returning some of its linked entities exploded, such asResource,Activity,Applicantetc.
The client gets all bookings with .../rest/bookings and the JSON response includes links for the linked entities. If it adds ?projection=details then the linked entities are exploded and returned. And this is great.
Now I add this custom method to the repository:
List<Booking> findByApplicant(@Param("applicant") Person applicant);
When the client invokes it with .../rest/bookings/search/findByApplicant?applicant=5, there seem to be no way to request the details projection. Following attempts are ignored:
- adding
&projection=detailsto the query string making the method always return
BookingDetails:List<BookingDetails> findByApplicant(@Param("applicant") Person applicant);
Summarizing, custom search methods (findBy*) never return a projection. Unless you annotate the repository with @RepositoryRestResource(excerptProjection = BookingDetails.class), but this leads to some problems, first of all the client has to always use the same projection. How can we allow the user to use projections also with findBy* methods?
.../rest/bookings/search/findByApplicant?applicant=5is not very RESTful. What about.../rest/bookings?applicant=5? - user1907906/fooor/conquer/the/worldis completely irrelevant. That said, Spring Data REST leverages hypermedia to let clients navigate to the resources so the structure if the ids of the resources even becomes less that not relevant at all :). - Oliver Drotbohm