spring-hateoas

Spring Data REST returns http 405 asking for List of nested resources

喜夏-厌秋 提交于 2019-12-07 19:59:26
问题 I'm using Spring Boot 1.5.7, Spring Data REST, Spring HATEOAS, Hibernate, Spring Validation, Swagger. I'm exposing all my repositories via Spring Data REST. It works quite fine but I've a problem when I expose a nested list of objects. Let's see this example: @Entity public class TicketBundle extends AbstractEntity { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY,mappedBy="ticketBundle") @OnDelete(action = OnDeleteAction.NO_ACTION) private List

Deleting an association over REST in Spring Data REST+HATEOAS

一笑奈何 提交于 2019-12-07 11:56:55
问题 I wish to know how to delete a many-to-many association via a REST call. I am able to create records, and associated them, but do not understand how to delete. I have a Spring Boot project where i'm using REST and HATEOAS to by pass Services and Controllers and expose my Repository directly. I have a User Model/Domain class @Entity @Table(name = "usr") public class User implements Serializable { private static final long serialVersionUID = 1L; @Version private long version = 0; @Id

Changing the JSON format for spring-data-rest

半世苍凉 提交于 2019-12-07 02:32:13
问题 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? 回答1: 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

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

白昼怎懂夜的黑 提交于 2019-12-07 00:33:20
问题 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); }

Spring Data Rest: custom Converter<Entity, Resource> is never invoked

主宰稳场 提交于 2019-12-06 16:41:50
I'm trying to implement a custom Converter for an Entity to a Resource object with Spring Data Rest, but the Converter is never invoked. I'm following this documentation : If your project needs to have output in a different format, however, it’s possible to completely replace the default outgoing JSON representation with your own. If you register your own ConversionService in the ApplicationContext and register your own Converter, then you can return a Resource implementation of your choosing. That's what I've tried to do. I have a @Configuration class that extends

How to write paginated controller that expose resource or list of resource in spring-data-hatoas

若如初见. 提交于 2019-12-06 09:55:12
Using spring-data, I want to write two method for my Person entity. Person.java: public class Person { @Id String id; String name; Integer age; // getters/setters omitted for clarity } I have written also a PersonResouce : public class PersonResource extends Resource<Person> { public PersonResource(Person content, Link... links) { super(content, links); } } I have also added a PersonResourceAssembler : public class PersonResourceAssembler extends ResourceAssemblerSupport<Person, PersonResource> { public PersonResourceAssembler() { super(PersonController.class, PersonResource.class); } public

Spring Data Rest - PUT is not working for associated reference types?

只谈情不闲聊 提交于 2019-12-06 04:23:24
I have the following domain class implemented for a Spring Data Rest project. @Entity @Data public class Address { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private long addressID; private String houseName; private String apartmentNumber; @ManyToOne private City city; @ManyToOne private Country country; } Now I am creating an Address resource by sending a POST with following JSON. { "houseName":"Some House", "apartmentNumber":"13 B", "city": "http://localhost:8080/city/1" "country":"http://localhost:8080/countries/1" } When I send a PUT request to the

Feign and HAL/resources

二次信任 提交于 2019-12-06 04:14:55
问题 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

How to change the property name of an embbed collection in Spring Hateos

你。 提交于 2019-12-05 19:42:33
I am using Spring hateoas to generate a HAL interface. My code looks like this: @RequestMapping(method = RequestMethod.GET) public Resources<Resource<Type>> all() { List<Resource<Type>> sdf = typeRepository.all().stream().map(type -> { return new Resource<Type>(type, ControllerLinkBuilder.linkTo(this.getClass()).slash(type.getId()).withSelfRel()); }).collect(Collectors.toList()); Resources<Resource<Type>> resourcesType = new Resources<>(sdf); resourcesType.add(ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(this.getClass()).all()).withSelfRel()); return resourcesType; } And the

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

风流意气都作罢 提交于 2019-12-05 13:34:58
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 the context of a HAL API, as opposed to writing hard DTO classes for a custom controller and mapping