spring-hateoas

How to add custom methods to Spring Data Rest JPA implementation and leverage HATEOS support?

孤街醉人 提交于 2019-11-30 12:10:44
问题 I have a Spring Data Rest Repository controller that utilizes JPA for the query implementation, and I need to add some custom query methods that cannot be done using the standard queryByExample method that JPA supports. I have created an Impl class that has the necessary method, but I cannot get it to be recognized. I saw that I can utilize a standard Spring MVC Controller, but I want to have a unified API, and basically all I really want is to implement my own custom /search methods. Even

How to disable RepositoryRestHandlerMapping and EndpointHandlerMapping?

点点圈 提交于 2019-11-30 11:37:21
I am currently building an application with a REST interface, using Spring Boot, Hibernate and Spring-HATEOAS. My data model is defined as beans with @Entity annotation and I am using Spring's feature to automatically set up a Hibernate repository (Creating an interface extending PagingAndSortingRepository ). My application is completely annotation-driven, i.e., I have no web.xml but configure everything with the Spring annotations like @Configuration , @Bean etc., and start the application from my main method with the help of SpringApplication.run(MyApp.class, args); This works fine, but with

Make collection propertie render as relation instead of property in json HAL representaion

强颜欢笑 提交于 2019-11-30 09:55:47
问题 I got hal formatted response as this: { "name": "Publisher A", "bookPublishers": [ { "publishedDate": "2019-07-12T08:19:04.583+0000", "_links": { "publisher": { "href": "http://localhost:8080/api/publishers/1" }, "book": { "href": "http://localhost:8080/api/books/2" } } }, { "publishedDate": "2019-07-12T08:19:04.564+0000", "_links": { "publisher": { "href": "http://localhost:8080/api/publishers/1" }, "book": { "href": "http://localhost:8080/api/books/1" } } } ], "_links": { "self": { "href":

Spring Data REST: projection representation of single resource

荒凉一梦 提交于 2019-11-30 09:35:58
问题 I have a simple UserRepository which exposed using Spring Data REST . Here is the User entity class: @Document(collection = User.COLLECTION_NAME) @Setter @Getter public class User extends Entity { public static final String COLLECTION_NAME = "users"; private String name; private String email; private String password; private Set<UserRole> roles = new HashSet<>(0); } I've created a UserProjection class which looks the following way: @JsonInclude(JsonInclude.Include.NON_NULL) @Projection(types

Custom Spring MVC HTTP Patch requests with Spring Data Rest functionality

做~自己de王妃 提交于 2019-11-30 05:21:40
问题 What is the best practice for supporting HTTP PATCH in custom Spring MVC controllers? Particularly when using HATEOAS/HAL? Is there an easier way to merge objects without having to check for the presence of every single field in the request json (or writing and maintaining DTOs), ideally with automatic unmarshalling of links to resources? I know this functionality exists in Spring Data Rest, but is it possible to leverage this for use in custom controllers? 回答1: I do not think you can use the

How to remove the “_embedded” property in Spring HATEOAS

筅森魡賤 提交于 2019-11-30 03:53:12
I'm using Spring Boot and HATEOAS to build a REST API and when my API returns a collection, it is wrapped inside a "_embedded" property, like so: { "_links":{ "self":{ "href":"http://localhost:8080/technologies" } }, "_embedded":{ "technologies":[ { "id":1, "description":"A", "_links":{ "self":{ "href":"http://localhost:8080/technologies/1" } } }, { "id":2, "description":"B", "_links":{ "self":{ "href":"http://localhost:8080/technologies/2" } } } ] } } I want the response to be like this: { "_links":{ "self":{ "href":"http://localhost:8080/technologies" } }, "technologies":[ { "id":1,

How to add custom methods to Spring Data Rest JPA implementation and leverage HATEOS support?

一世执手 提交于 2019-11-30 02:08:30
I have a Spring Data Rest Repository controller that utilizes JPA for the query implementation, and I need to add some custom query methods that cannot be done using the standard queryByExample method that JPA supports. I have created an Impl class that has the necessary method, but I cannot get it to be recognized. I saw that I can utilize a standard Spring MVC Controller, but I want to have a unified API, and basically all I really want is to implement my own custom /search methods. Even with the custom controller, the problem is then that the HAL links and other related items are no longer

How do I avoid n+1 queries with Spring Data Rest?

你。 提交于 2019-11-29 19:39:14
Question. How do I avoid n+1 queries with Spring Data REST? Background. When querying Spring Data REST for a list of resources, each of the resulting top-level resources has links to the associated resources, as opposed to having the associated resources embedded directly in the top-level resources. For example, if I query for a list of data centers, the associated regions appear as links, like this: { "links" : [ { "rel" : "self", "href" : "http://localhost:2112/api/datacenters/1" }, { "rel" : "datacenters.DataCenter.region", "href" : "http://localhost:2112/api/datacenters/1/region" } ],

Returned json unexpected, has “links” spelled as “_links” and structure different, in Spring hateoas

匆匆过客 提交于 2019-11-29 18:09:59
问题 As the title says, I have a resource object Product extending ResourceSupport . However, the responses I receive have the property "_links" instead of "links" and have a different structure. { "productId" : 1, "name" : "2", "_links" : { "self" : { "href" : "http://localhost:8080/products/1" } } } Based on the HATEOAS Reference, the expected is: { "productId" : 1, "name" : "2", "links" : [ { "rel" : "self" "href" : "http://localhost:8080/products/1" } ] } Was this intended? Is there a way to

Spring Rest: Cannot insert rows that have @ManyToOne column

和自甴很熟 提交于 2019-11-29 17:26:57
I am following a spring getting started tutorial in https://spring.io/guides/gs/accessing-data-rest/ I added another entity books that has @ManyToOne relation to Person entity. Person entity has a new property called bikes and has a @OneToMany relation with Bike entity. Only thing that is different from the getting started project is the new attribute with its getter and setter: package hello; import java.util.List; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany;