spring-data-rest

How can I simply add a link to a Spring Data REST Entity

守給你的承諾、 提交于 2019-12-04 03:16:32
I have my Entities with Spring Data JPA, but to generate stats about them, I use jOOQ in a Spring @Repository . Since my methods return either a List of entities, or a Double , how can I expose them as links? Let's say I have a User entity, I want to get the following JSON: { "_embedded" : { "users" : [ ] }, "_links" : { "self" : { "href" : "http://localhost:8080/api/users" }, "stats" : { "href" : "http://localhost:8080/api/users/stats" } "profile" : { "href" : "http://localhost:8080/api/profile/users" } }, "page" : { "size" : 20, "totalElements" : 0, "totalPages" : 0, "number" : 0 } } And in

How to restrict access by role to a Spring Data REST projection?

浪子不回头ぞ 提交于 2019-12-04 02:44:42
In an application using Spring Data JPA and Spring Data REST, let's say you have an entity class like this: @Entity public class Person { @Id @GeneratedValue private int id; private String name; @JsonIgnore private String superSecretValue; ... } We want Spring Data REST to expose all of this entity's fields EXCEPT for superSecretValue , and so we've annotated that field with @JsonIgnore . However, in some cases we DO want access to superSecretValue , and so we create a projection that will return all of the fields including that one: @Projection(name = "withSecret", types = {Person.class})

Is it possible to use spring-data-rest-webmvc without an actual Repository?

我只是一个虾纸丫 提交于 2019-12-04 02:15:34
问题 The question may sound funny but I think this should be possible. What I want is to use a repository that is purely custom but is exposed just like a Repository. This service would have methods to get, save, delete and list objects where the data could be from any arbitrary source. Looking through the code, I think it should be possible since methods are accessed using CrudMethods and RepositoryInvoker . I belief this requires an implementation of RepositoryFactoryInformation that will be

Hibernate DefaultEntityAliases raises NullPointerException

↘锁芯ラ 提交于 2019-12-03 23:39:24
问题 I'm using Spring Boot, Spring Data REST, Hibernate (5.2.12.Final) and I'm exposing my repositories as REST services. I've a problem with a query that raises a NullPointerException and I don't understand the reason. I'm calling this method via a HTTP request (this is exposed by Spring Data REST). This is the code: @Transactional(readOnly = true) @PreAuthorize("isAuthenticated()") public interface CheckPointRepository extends JpaRepository<CheckPoint, Long> { @Query(value = "SELECT * FROM

JSON parse error: Can not construct instance of java.time.LocalDate: no String-argument constructor/factory method to deserialize from String value

Deadly 提交于 2019-12-03 22:14:22
I am new to Spring Data REST project and I am trying to create my first RESTful service. The task is simple, but I am stuck. I want to perform CRUD operations on a user data stored in an embedded database using RESTful API. But I cannot figure out how to make the Spring framework process the birthData as "1999-12-15" and store it as a LocalDate. The @JsonFormat annotation does not help. At present I get the error: HTTP/1.1 400 Content-Type: application/hal+json;charset=UTF-8 Transfer-Encoding: chunked Date: Thu, 24 Aug 2017 13:36:51 GMT Connection: close {"cause":{"cause":null,"message":"Can

Spring Data Rest Add custom endpoint to specific reposiotry

淺唱寂寞╮ 提交于 2019-12-03 21:20:03
问题 I would like to add a custom search endpoint to my existing user repository. My user Repository looks like this: @RepositoryRestResource(collectionResourceRel="users", path="users") public interface UserRepository extends PagingAndSortingRepository<User, Long>{ User findByUsername(String username); } The custom controller: @BasePathAwareController @RequestMapping("users/search") public class CustomController implements ResourceProcessor<RepositorySearchesResource>, ResourceAssembler<User,

Spring HATEOAS versus Spring Data Rest

醉酒当歌 提交于 2019-12-03 18:22:11
问题 Question is, what's the difference between Spring HATEOAS versus Spring Data Rest ? I feel both can do the same, and Spring Data Rest (as part of Spring Data) seems a bit more alive. https://github.com/spring-projects/spring-hateoas https://github.com/spring-projects/spring-data-rest When would you use one or the other? 回答1: Spring HATEOAS provides common abstractions (representational models, a Link class, API to build links pointing to Spring MVC controllers, etc.) to ease building

How can I handle exceptions with Spring Data Rest and the PagingAndSortingRepository?

夙愿已清 提交于 2019-12-03 17:39:33
问题 Let's say I have a repository like: public interface MyRepository extends PagingAndSortingRepository<MyEntity, String> { @Query("....") Page<MyEntity> findByCustomField(@Param("customField") String customField, Pageable pageable); } This works great. However, if the client sends a formed request (say, searching on a field that does not exist), then Spring returns the exception as JSON. Revealing the @Query , etc. // This is OK http://example.com/data-rest/search/findByCustomField?customField

Spring Data Rest - _links

心不动则不痛 提交于 2019-12-03 17:21:16
Edit 14/08/14 13:29 My next conclusion is that the hal+json format produced from my @RepositoryRestResource CrudRepository is incorrect. The tutorial ( http://spring.io/guides/gs/accessing-data-rest/ ) shows the output of a hypermedia Rest JPA entity as: (please note there is no "rel" element, and "links" is not an array) { "_links" : { "people" : { "href" : "http://localhost:8080/people{?page,size,sort}" } } } However, the reference docs ( http://docs.spring.io/spring-data/rest/docs/1.1.x/reference/html/intro-chapter.html ) show that the output should be: { "links" : [ { "rel" : "customer",

Spring Data Rest: how to register a custom conversionService with custom Converter<Entity, Resource>?

↘锁芯ラ 提交于 2019-12-03 17:04:36
There is something that is not enough clear in this part of Spring Data Rest documentation: The Spring Data REST exporter executes any discovered ResourceProcessor`s before it creates the output representation. For what I have noticed, it's true: ResourceProcessor are invoked during the handling of the request, after the completion of RepositoryEntityController respective method. It does this by registering a Converter<Entity, Resource> instance with an internal ConversionService. I don't understand when it is used this Converter<Entity,Resource> . This is the component responsible for