I am building a REST API with Dropwizard and JDBI and I need to work with different representations of the same resource.
An example where we are working with a events
resource:
A event
resource has properties field1
, field2
, field3
and field4
.
- When creating a new event by doing
POST /events
the request body should contain all properties. - When fetching an event by doing
GET /event/1
as a normal user the response body should only containfield1
andfield2
. - When fetching an event by doing
GET /event/1
as a super user the response body should containfield1
,field2
andfield3
.
What is the best (simple) way of dealing with this (#2 and #3) when it comes to the resource bean, the jdbi query and the resource mapper?
Separate bean/mapper/query for each representation (not very DRY, even with a base bean that is extended)? Filtering the response object after it's been built (not very elegant and possibly brittle, easy to accidentally expose too much data)?