Baiteman Baiteman - 9 months ago 138
reST (reStructuredText) Question

Expose all IDs when using Spring Data Rest

I'd like to expose all IDs using a Spring Rest interface.
I know that per default an ID like this

@Column(unique=true, nullable=false)
private Long id;

will not be exposed via the rest interface.

I'm aware that I can use this

public class RepositoryConfig extends RepositoryRestMvcConfiguration {
protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {

to expose the IDs for the user.

But is there an easy way to expose all of my IDs without manually maintaing a list in this configureRepository method?

Thanks in advance!


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).