Expose all IDs when using Spring Data Rest

If you want to expose the id field for all your entity classes: import java.util.stream.Collectors; import javax.persistence.EntityManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.data.rest.core.config.RepositoryRestConfiguration; import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter; @Configuration public class MyRepositoryRestConfigurerAdapter extends RepositoryRestConfigurerAdapter { @Autowired private EntityManager entityManager; @Override public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { config.exposeIdsFor(entityManager.getMetamodel().getEntities().stream().map(e -> e.getJavaType()).collect(Collectors.toList()).toArray(new Class[0])); } }

Creating multiple aliases for the same QueryDSL path in Spring Data

You can create a transient property bound to QueryDSL this way: @Transient @QueryType(PropertyType.SIMPLE) public String getNameEndsWith() { // Whatever code, even return null } If you are using the QueryDSL annotation processor, you will see the “nameEndsWith” in the metadata Qxxx class, so you can bind it like any persisted property, but without persisting it.

Is it problematic that Spring Data REST exposes entities via REST resources without using DTOs?

tl;dr No. DTOs are just one means to decouple the server side domain model from the representation exposed in HTTP resources. You can also use other means of decoupling, which is what Spring Data REST does. Details Yes, Spring Data REST inspects the domain model you have on the server side to reason about the … Read more

Spring HATEOAS versus Spring Data Rest

Spring HATEOAS provides common abstractions (representational models, a Link class, API to build links pointing to Spring MVC controllers, etc.) to ease building hypermedia driven REST APIs with Spring MVC in general. Thus, you can use it alongside Spring MVC to manually build those services. Spring Data REST uses Spring HATEOAS to automatically expose resources … Read more

Disable Hypertext Application Language (HAL) in JSON?

(Hyper)media types The default settings for Spring Data REST use HAL as the default hypermedia representation format, so the server will return the following for the given Accept headers: No header -> application/hal+json -> HAL application/hal+json -> application/hal+json -> HAL application/json -> application/json -> HAL (this is what the default configures) application/x-spring-data-verbose+json -> application/x-spring-data-verbose+json -> … Read more

How to consume Page response using Spring RestTemplate

new TypeReference<Page<StoryResponse>>() {} The problem with this statement is that Jackson cannot instantiate an abstract type. You should give Jackson the information on how to instantiate Page with a concrete type. But its concrete type, PageImpl, has no default constructor or any @JsonCreators for that matter, so you can not use the following code either: … Read more