Is there any way to use a @Projection interface as the default representation for a resource in SDR? Either through the SDR repositories or through a custom controller?
It used to be possible in a custom controller to do this by injecting a ProjectionFactory
and using the createProjection
method, but this has been broken by a recent Spring Data Rest update.
I would like to enforce a particular view on an entity, and the SDR projections seem like an ideal method for doing this, especially in the context of a HAL API, as opposed to writing hard DTO classes for a custom controller and mapping between them etc. Excerpt projections are not what I am after, as these only apply when looking at an associated resource.
@Bean
in some@Configuration
file e.g.@Configuration class SomeConfig { @Bean public SpelAwareProxyProjectionFactory projectionFactory() { return new SpelAwareProxyProjectionFactory(); } }
source – Gimcrackery