spring-hateoas

Changing the JSON format for spring-data-rest

柔情痞子 提交于 2019-12-05 07:20:53
Currently spring-data-rest is returning JSON in HAL format in a spring-boot project of mine. I am using an ember.js frontend and want to use jsonapi ( http://jsonapi.org/ ) specification. How might I register a new JSON formatting strategy given I will need to write the formatter myself as one does not exists yet? This is how you can customize the HATEOAS that Spring Data REST produces: https://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.customizing-json-output If you need to completely replace the JSON representation with your own, then you can write and

How can I get Spring MVC+HATEOAS to encode a list of resources into HAL?

时光总嘲笑我的痴心妄想 提交于 2019-12-05 04:11:07
I have a Spring HATEOAS Resource such that ModelResource extends Resource<Model> . In a @RestController I have a method to create new Model s: @RequestMapping(value = "", method = POST) public ResponseEntity<ModelResource> postModel() { Model model = service.create().model; ModelResource resource = assembler.toResource(model); HttpHeaders headers = new HttpHeaders(); headers.setLocation(URI.create(resource.getLink("self").getHref())); return new ResponseEntity<>(resource, headers, CREATED); } The created ModelResource returned from the above method is HAL-encoded: $ curl -v -XPOST localhost

Spring Data Rest Ambiguous Association Exception

天大地大妈咪最大 提交于 2019-12-05 02:04:46
The newly added LinkCollectingAssociationHandler is throwing a MappingException due to an ambiguous association in my domain class. The links array looks like this: [<http://localhost:8080/rooms/2/roomGroups>;rel="roomGroups", <http://localhost:8080/rooms/2/userGroup>;rel="userGroup", <http://localhost:8080/rooms/2/room>;rel="room", <http://localhost:8080/rooms/2/originatingConferences>;rel="originatingConferences", <http://localhost:8080/rooms/2/user>;rel="user"] And it is trying to add another 'room' relation when it throws the exception. The issue is that it seems to be adding links to

Spring Data Rest - Add link to search endpoint

落花浮王杯 提交于 2019-12-05 01:24:19
问题 In our Spring-Data-Rest Project we have a custom (fuzzy) search on a /buergers/search/findBuergerFuzzy?searchString="..." endpoint. Is it possible to add a link for it on the /buergers/search endpoint (Without overriding the automatically exposed Repository findBy Methods)? The Controller exposing the search: @BasePathAwareController @RequestMapping("/buergers/search/") public class BuergerSearchController { @Autowired QueryService service; @RequestMapping(value = "/findBuergerFuzzy", method

Spring Data Rest / Spring Hateoas Custom Controller - PersistentEntityResourceAssembler

Deadly 提交于 2019-12-04 22:50:20
问题 I'm attempting to add some additional business logic to the auto-generated endpoints from the RepositoryRestResource. Please see the code below: Resource: @RepositoryRestResource(collectionResourceRel="event", path="event") public interface EventRepository extends PagingAndSortingRepository<Event, Long> { } Controller: @RepositoryRestController @RequestMapping(value = "/event") public class EventController { @Autowired private EventRepository eventRepository; @Autowired private

Defining a resource assembler for a REST Spring HATEOAS controller

烂漫一生 提交于 2019-12-04 18:28:12
问题 I'm trying to add HATEOAS links to a JSON resource served by a Spring REST controller. I see I should use a resource assembler as described at https://github.com/spring-projects/spring-hateoas The example displays a Person class and a PersonResource class. I understand the PersonResource class is defined as: public class PersonResource extends ResourceSupport { } What is then the Person class ? Is it a data domain class ? In my case, I have defined an Admin class that is a REST domain class,

Document HAL “_links” from Spring Hateoas (with swagger)? [closed]

空扰寡人 提交于 2019-12-04 18:17:21
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I have a REST service I want to document for my client developing team. So I added some Links from Spring-Hateoas to my resources API, and plugged into it swagger-springmvc @Api... annotations to document everything and make a good API reference for my Angular team to be able to understand my REST service. The

Spring HATEOAS Resource Assembler and Resource Links with many variables

烈酒焚心 提交于 2019-12-04 11:45:48
I'm working on REST API with Spring HATEOAS and the Spring stack, and i have some problems with links into resources. Here is my code : the Controller : @RestController @RequestMapping("/apporteurs/{idInt}/ribs") public class RibController { @Autowired private RibResourceAssembler ribResourceAssembler; @Autowired private RibRepository ribRepository; /** * Methode GET permettant d'obtenir un Rib par son ID * * @param idRib ID du Rib * @return RibResource */ @RequestMapping(value = "/{idRib}", method = RequestMethod.GET) @ResponseBody public RibResource getRibById(@PathVariable Long idInt,

Adding more information to the HATEOAS response in Spring Boot Data Rest

我只是一个虾纸丫 提交于 2019-12-04 11:43:33
I have the following REST controller. @RepositoryRestController @RequestMapping(value = "/booksCustom") public class BooksController extends ResourceSupport { @Autowired public BooksService booksService; @Autowired private PagedResourcesAssembler<Books> booksAssembler; @RequestMapping("/search") public HttpEntity<PagedResources<Resource<Books>>> search(@RequestParam(value = "q", required = false) String query, @PageableDefault(page = 0, size = 20) Pageable pageable) { pageable = new PageRequest(0, 20); Page<Books> booksResult = BooksService.findBookText(query, pageable); return new

Feign and HAL/resources

半腔热情 提交于 2019-12-04 11:17:50
I've got a server that exposes resources through spring-data-rest and this uses, as far as I understand HAL or HATEOAS. But when I try to use it in combination with Feign, I can't seem to be able to register a Jackson2HalModule that gets picked up. Is there something I have to do to connect the Feign "client" to the new converter? Does it use another ObjectMapper than the one I got here? Code: @Inject public void configureObjectMapper(ObjectMapper mapper, RestTemplate template) { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.registerModule(new