spring-hateoas

Converter from @PathVariable DomainObject to String? (using ControllerLinkBuilder.methodOn)

China☆狼群 提交于 2019-12-01 17:35:25
I'm trying to call Spring's ControllerLinkBuilder.methodOn() with a non-String type, which always fails. And I don't know which kind of Converter to use and where to register it. Here's my Controller: @RestController @RequestMapping("/companies") class CompanyController { @RequestMapping(value="/{c}", method=RequestMethod.GET) void getIt(@PathVariable Company c) { System.out.println(c); Link link = linkTo(methodOn(getClass()).getIt(c)); } } The System.out.println(c) works well. My Company Domain object get's fetched from DB. (I'm using DomainClassConverter ) But the other way doesn't work:

Converter from @PathVariable DomainObject to String? (using ControllerLinkBuilder.methodOn)

守給你的承諾、 提交于 2019-12-01 17:08:38
问题 I'm trying to call Spring's ControllerLinkBuilder.methodOn() with a non-String type, which always fails. And I don't know which kind of Converter to use and where to register it. Here's my Controller: @RestController @RequestMapping("/companies") class CompanyController { @RequestMapping(value="/{c}", method=RequestMethod.GET) void getIt(@PathVariable Company c) { System.out.println(c); Link link = linkTo(methodOn(getClass()).getIt(c)); } } The System.out.println(c) works well. My Company

Spring Data ReST ref link omission when null or empty

倾然丶 夕夏残阳落幕 提交于 2019-12-01 12:57:33
I've been scouring the docs and the Restbucks implementation by Oliver but I don't seem to be able to configure the links on a generated Spring REST repository resource. (I can add to them, but cannot remove them via the ResourceProcessor as the processor is invoked prior to conversion by the looks of things) My case is quite simple and that is I wish to omit rel links on objects that point to null or an empty collections (such as in the case of say a graph node parent/child structure) Would anybody have any incite as to how I could achieve this? Ideally I would like to have something

Spring Data ReST ref link omission when null or empty

偶尔善良 提交于 2019-12-01 11:39:54
问题 I've been scouring the docs and the Restbucks implementation by Oliver but I don't seem to be able to configure the links on a generated Spring REST repository resource. (I can add to them, but cannot remove them via the ResourceProcessor as the processor is invoked prior to conversion by the looks of things) My case is quite simple and that is I wish to omit rel links on objects that point to null or an empty collections (such as in the case of say a graph node parent/child structure) Would

Is there a means to set the host & port for the Spring HATEOAS `ControllerLinkBuilder`?

落花浮王杯 提交于 2019-12-01 04:58:07
Spring HATEOAS provides the handy ControllerLinkBuilder to create links to controller methods, which will be added as hrefs in the JSON/XML returned to a client. For instance: resource.add(linkTo(methodOn(FooController.class) .findFoo(entity.getClient().getId())) .withRel("show")); ... might generate JSON a bit like: { "name":"foo", "links":[ {"rel":"show","href":"http://111.11.11.111:28080/foos/1"} ] } However... I tend to access my services through a reverse proxy. Which I guess most people probably would. This lets me have multiple services running on different ports, but lets me access

Is there a means to set the host & port for the Spring HATEOAS `ControllerLinkBuilder`?

泄露秘密 提交于 2019-12-01 02:31:27
问题 Spring HATEOAS provides the handy ControllerLinkBuilder to create links to controller methods, which will be added as hrefs in the JSON/XML returned to a client. For instance: resource.add(linkTo(methodOn(FooController.class) .findFoo(entity.getClient().getId())) .withRel("show")); ... might generate JSON a bit like: { "name":"foo", "links":[ {"rel":"show","href":"http://111.11.11.111:28080/foos/1"} ] } However... I tend to access my services through a reverse proxy. Which I guess most people

Canonical _links with Spring HATEOAS

好久不见. 提交于 2019-11-30 21:42:58
We're building a RESTful web service similiar to the spring.io guide " Accessing JPA Data with REST ". To reproduce the sample outputs below, it suffices to add a ManyToOne -Relation to Person as follows: // ... @Entity public class Person { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; private String firstName; private String lastName; @ManyToOne private Person father; // getters and setters } A GET request after adding some sample data yields: { "firstName" : "Paul", "lastName" : "Mustermann", "_links" : { "self" : { "href" : "http://localhost:8080/people/1" }, "father

Custom Spring MVC HTTP Patch requests with Spring Data Rest functionality

。_饼干妹妹 提交于 2019-11-30 21:00:00
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? I do not think you can use the spring-data-rest functionality here. spring-data-rest is using json-patch library internally. Basically I

Spring Data Rest - Caching

≯℡__Kan透↙ 提交于 2019-11-30 13:31:08
问题 How to enable caching with Spring Data Rest? The reasoning behind is that repository listing and search methods won't change once the application is up. Also if the data behind the rest API is changed only through rest API it does makes a case to enable caching data too. I believe some level is caching happens in REST API framework and it would be ideal if the caching happens at the final response stage i.e., json response (to avoid the overhead of marshalling objects to json) Thoughts

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

試著忘記壹切 提交于 2019-11-30 12:59:08
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 change it, or at leas the "link" if not the structure? I added the selfLink through the following