spring-hateoas

Using a Spring Data Rest @Projection as a representation for a resource in a custom controller

南笙酒味 提交于 2019-12-22 09:09:30
问题 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

Generate links with additional query parameters using PagedResourcesAssembler

Deadly 提交于 2019-12-22 06:56:02
问题 I'm using spring-data-common's PagedResourcesAssembler in my REST controller, and I was happy to see it even generates next/previous links in the response. However, in those cases where I have additional query parameters (besides page, size, sort), these are not included in the generated links. Can I somehow configure the assembler to include the parameters in the links? Many thanks, Daniel 回答1: You need to build base link by yourself and pass it to "toResource" method of

spring HATEOAS links issue for HTTP and HTTPS

六月ゝ 毕业季﹏ 提交于 2019-12-22 06:02:23
问题 I am using Spring HATEOAS in my web application. My application runs behind a Nginx webserver. I am sending following url with HTTPS header GET https://national.usa.com/testapp-rest/api/user/654rtrtet-5grt-fgsdf-dfgs-765ytrtsdhshfgsh/newAuthentication Status Code:200 OK Response Headersview sourceAccess-Control-Allow-Headers:x-requested-with, Accept, Content-Type, Origin, Authorization, X-Auth-Token Access-Control-Allow-Methods:POST, GET, OPTIONS, PUT, DELETE Access-Control-Allow-Origin:*

spring HATEOAS links issue for HTTP and HTTPS

爱⌒轻易说出口 提交于 2019-12-22 06:01:37
问题 I am using Spring HATEOAS in my web application. My application runs behind a Nginx webserver. I am sending following url with HTTPS header GET https://national.usa.com/testapp-rest/api/user/654rtrtet-5grt-fgsdf-dfgs-765ytrtsdhshfgsh/newAuthentication Status Code:200 OK Response Headersview sourceAccess-Control-Allow-Headers:x-requested-with, Accept, Content-Type, Origin, Authorization, X-Auth-Token Access-Control-Allow-Methods:POST, GET, OPTIONS, PUT, DELETE Access-Control-Allow-Origin:*

Template variables with ControllerLinkBuilder

江枫思渺然 提交于 2019-12-21 03:36:21
问题 I want my response to include this: "keyMaps":{ "href":"http://localhost/api/keyMaps{/keyMapId}", "templated":true } That's easy enough to achieve: add(new Link("http://localhost/api/keyMaps{/keyMapId}", "keyMaps")); But, of course, I'd rather use the ControllerLinkBuilder, like this: add(linkTo(methodOn(KeyMapController.class).getKeyMap("{keyMapId}")).withRel("keyMaps")); The problem is that by the time the variable "{keyMapId}" reaches the UriTemplate constructor, it's been included in an

Spring Boot's TestRestTemplate with HATEOAS PagedResources

半世苍凉 提交于 2019-12-19 09:05:30
问题 I'm trying to use the TestRestTemplate in my Spring Boot Application's Integration-Test, to make a request to a Spring Data REST Repository. The response in the browser has the form: { "links": [ { "rel": "self", "href": "http://localhost:8080/apiv1/data/users" }, { "rel": "profile", "href": "http://localhost:8080/apiv1/data/profile/users" }, { "rel": "search", "href": "http://localhost:8080/apiv1/data/users/search" } ], "content": [ { "username": "admin", "enabled": true, "firstName": null,

Date format in the json output using spring boot

与世无争的帅哥 提交于 2019-12-18 10:10:28
问题 I am working on spring boot for creating a REST application. And I have a DTO as shown below: public class Subject { private String uid; private String number; private String initials; private Date dateOfBirth; And I use Spring-Hateos and the reurn type of my controller is ResponseEntity<Resources<Resource<Subject>>> . I need the date to be displayed in the "yyyy-mm-dd" format. 回答1: If you have Jackson integeration with your application to serialize your bean to JSON format, then you can use

How to change HAL links format using Spring HATEOAS

痴心易碎 提交于 2019-12-17 23:18:39
问题 I'm building a Spring REST application using Spring HATEOAS (0.16.0.RELEASE) and I'd like the JSON links output to look like: _links: { self: { href: "https://<ip>/api/policies/321" } } while it renders like: "links": [{ "rel":"self", "href":"http://<ip>/api/policies/321" }] I'm using HATEOAS Resource and ResourceAssembler . Why do I get this format instead of the other? How can I change it? 回答1: In order to use HAL as the message format language for our RESTful API, and enable automatic

Spring Data Rest Without HATEOAS

别等时光非礼了梦想. 提交于 2019-12-17 18:36:08
问题 I really like all the boilerplate code Spring Data Rest writes for you, but I'd rather have just a 'regular?' REST server without all the HATEOAS stuff. The main reason is that I use Dojo Toolkit on the client side, and all of its widgets and stores are set up such that the json returned is just a straight array of items, without all the links and things like that. Does anyone know how to configure this with java config so that I get all the mvc code written for me, but without all the

When to use @RestController vs @RepositoryRestResource

不想你离开。 提交于 2019-12-17 17:26:36
问题 I have been looking at various examples of how to use Spring with REST . Our end target is a Spring HATEOAS/HAL setup I have seen two distinct methods for rendering REST within Spring Via @RestController within a Controller Via @RepositoryRestResource within a Repository The thing I am struggling to find is why would you use one over the other. When trying to implement HAL which is best? Our database backend is Neo4j . 回答1: Ok, so the short story is that you want to use the