Issue
I'd like to expose all IDs using a Spring Rest interface.
I know that per default an ID like this will not be exposed via the rest interface:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(unique=true, nullable=false)
private Long id;
I'm aware that I can use this to expose the ID for User
:
@Configuration
public class RepositoryConfig extends RepositoryRestMvcConfiguration {
@Override
protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.exposeIdsFor(User.class);
}
}
But is there an easy way to expose all IDs without manually maintaining a list in this configureRepositoryRestConfiguration
method?
Solution
Currently, there is no way to do this provided by SDR. This issue on the SDR Jira tracker gives some explanation as to why this isn't (and perhaps shouldn't) be possible.
The argument is basically that since the IDs are already contained within the self
links in the response, you don't need to expose them as properties of the object itself.
That said, you may be able to use reflection to retrieve all classes that have a javax.persistence.Id
annotation and then call RepositoryRestConfiguration#exposeIdsFor(Class<?>... domainTypes)
.
Answered By - Justin Lewis