spring-hateoas

Spring Data-Rest POST to sub-resource

梦想与她 提交于 2020-01-04 23:06:21
问题 Lets say I have the following structure: @Entity class Person extends AbstractPersistable<Long> { String name String surname } @Entity class Task extends AbstractPersistable<Long> { String description @ManyToOne Person person } If I follow proper HAL guidelines I'm not supposed to expose entity id's. Since I don't have a bi-directional relationship I cant PUT or PATCH to http://localhost:8080/persons . Even if I did create the relation, I probably wouldn't want to first POST the Task to

Spring Hateoas ControllerLinkBuilder adds null fields

江枫思渺然 提交于 2020-01-03 07:32:11
问题 I'm following a tutorial on Spring REST and am trying to add HATEOAS links to my Controller results. I have a simple User class and a CRUD controller for it. class User { private int id; private String name; private LocalDate birthdate; // and getters/setters } Service: @Component class UserService { private static List<User> users = new ArrayList<>(); List<User> findAll() { return Collections.unmodifiableList(users); } public Optional<User> findById(int id) { return users.stream().filter(u -

How do I expose a new REST method to through a Spring Data MongoDB repository with ALPS/HATEOAS metadata?

帅比萌擦擦* 提交于 2020-01-02 08:47:28
问题 How do I expose a new method in a MongoRepository extension class to the generated REST API and include the same ALPS/HATEOAS metadata, links etc. I have the usual Spring Data MongoDB repository: public interface CollectionRepository extends Repository<Collection, String> { // Simple queries Collection findFirstByName(@Param("name") String name); } Now I want to add another method and have it integrate into the generated Repository REST API so that it is included in the {repository}

Spring MVC + DeferredResult add Hateoas stuff

醉酒当歌 提交于 2020-01-02 04:46:10
问题 For the rest interface the Spring MVC + RxJava + DeferredResult returned from controllers is used. I am thinking about adding Hateoas support to the endpoints. The natural choice would be the Spring Hateoas . The problem is that Spring Hateoas would not work in the asynchronous/multi-threading environment since it uses ThreadLocal . Is there any way to workaround that constraint? I do not think so but maybe someone has any suggestions. Has anyone used other APIs to add Hateoas support to the

Canonical _links with Spring HATEOAS

怎甘沉沦 提交于 2019-12-30 06:53:07
问题 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",

Spring Data Rest PUT v.s PATCH LinkableResources

。_饼干妹妹 提交于 2019-12-30 02:17:09
问题 I'm using Spring Data REST to expose my Entity's and their relationships. I have a OneToOne relationship between two Entity's and I'm trying to update/change the relationship with PUT and PATCH. I noticed that Spring Data REST will only allow you to update linked resources - JPA mapped Entity's (OneToMany, ManyToOne, etc) which are also AggregateRoots (has a Repository) - via a PATCH and are ignored with a PUT . This can be seen in the LinkedAssociationSkippingAssociationHandler class: if

Spring Data REST custom query integration

二次信任 提交于 2019-12-28 08:12:10
问题 I want to create a REST link for an Employee entity that will basically be a findByAllFields query. Of course this should be combined with Page and Sort . In order to do that I have implemented the following code: @Entity public class Employee extends Persistable<Long> { @Column private String firstName; @Column private String lastName; @Column private String age; @Column @Temporal(TemporalType.TIMESTAMP) private Date hiringDate; } So I would like to have lets say a query where I can do: http

Spring Data REST custom query integration

筅森魡賤 提交于 2019-12-28 08:12:01
问题 I want to create a REST link for an Employee entity that will basically be a findByAllFields query. Of course this should be combined with Page and Sort . In order to do that I have implemented the following code: @Entity public class Employee extends Persistable<Long> { @Column private String firstName; @Column private String lastName; @Column private String age; @Column @Temporal(TemporalType.TIMESTAMP) private Date hiringDate; } So I would like to have lets say a query where I can do: http

Maven incorrect dependancy version resolution

梦想的初衷 提交于 2019-12-25 03:22:55
问题 When including the latest Spring Hateoas Starter, Maven is downloading the incorrect Spring Hateoas. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-hateoas</artifactId> <version>2.2.0.M1</version> </dependency> When I run the maven dependency tree I get the following: > mvn dependency:tree | grep hateoas INFO] +- org.springframework.boot:spring-boot-starter-hateoas:jar:2.2.0.M1:compile [INFO] | +- org.springframework.hateoas:spring-hateoas:jar:0.25.1

Spring Boot REST Resource not showing linked objects (sets)

﹥>﹥吖頭↗ 提交于 2019-12-24 15:59:29
问题 I've a database and some classes. These classes are linked with OneToMany , and so on. If I print the object itself with spring it contains everything. But if I print it with the Resource feature, it contains only the variables, which are no collections or linked otherwise with an other class. How can I add the collections to the output? 回答1: By default Spring Data REST does not show associated resources except as links. If you want that you have to define projections that describe the fields