spring-data-rest

LocalDateTime is not converted to String but to Json object

大憨熊 提交于 2019-12-05 21:11:30
I want to serialize a creation date of type java.time.LocalDateTime as String, when calling a spring-data-rest service. The field of the entity is annotated with DateTimeFormat(iso=ISO.DATE_TIME). I also registered a LocalData to String Converter in the Spring Configuration class. @Override @Bean protected ConversionService neo4jConversionService() throws Exception { ConversionService conversionService = super.neo4jConversionService(); ConverterRegistry registry = (ConverterRegistry) conversionService; registry.removeConvertible(LocalDateTime.class, String.class); registry.removeConvertible

How to determine which properties of a RESTful resource have changed before save when using Spring Data REST repositories?

本小妞迷上赌 提交于 2019-12-05 20:11:10
If I have the following resource published by Spring Data REST... { "status": "idle" } How could I react to a PATCH or PUT that changes the value of property status ? The idea would be to trigger some server process based on a property change. Ideally this would happen before save and it would be possible to compare the new version of the resource with the previously-persisted version. You would usually use a @RepositoryEventHandler to hook up your event logic - see the documentation for details . I do not know of a function to directly get the changed properties. But if you use a

Spring Data REST: How to retrieve many items using list of Ids in one single call?

橙三吉。 提交于 2019-12-05 20:10:17
I can retrieve one single book from Spring Data REST with a call such as: GET /book/{id} Now, if I know the Ids of two books and I want to retrieve them all at once? What should the call be? I tried the following but it is returning me different books than the specified ones: GET /book?ids=id1,id2 You could declare a query method in your Repository interface like this: List<Book> findByIdIn(@Param("ids") Long[] ids); So that you can request books this way: GET /book/search/findByIdIn?ids=1,6,9 来源: https://stackoverflow.com/questions/27013726/spring-data-rest-how-to-retrieve-many-items-using

How to set the default media type for spring-data-rest?

房东的猫 提交于 2019-12-05 19:16:49
From RepositoryRestConfiguration I can see that setting spring.data.rest.default-media-type=application/json could change the default media type served by @RepositoryRestResource . @SuppressWarnings("deprecation") public class RepositoryRestConfiguration { private MediaType defaultMediaType = MediaTypes.HAL_JSON; } Question: as this class is in deprecation , what is the correct way to set/override the default type? You can do this via RepositoryRestConfiguration or simply with a property in your application.properties. See the documentation here . The RepositoryRestConfiguration class is NOT

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

断了今生、忘了曾经 提交于 2019-12-05 18:22:04
问题 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

Spring Data Rest and custom repositories

眉间皱痕 提交于 2019-12-05 16:27:56
Is it possible to export REST resources with custom (spring data) repositories? How does it work? I cannot find any example. I also have not found any claim that it is impossible. Jay Spring data rest specifically detects and does not export custom implementations on repositories. See the reference to the codebase here and the reason why here . If you want to expose a custom repository implementation, you will need to use a custom controller. Documentation for how to appropriately use custom controllers is slated for Spring Data Rest 2.4 . We used these two methods and both work fine so far:

Spring not loading data even with FetchType.EAGER set

做~自己de王妃 提交于 2019-12-05 16:00:57
I have two models I'm trying to get data back from a REST API (Pet and Media). I'm trying to get the oneToMany relationship between pet and media eagerly loaded via the FetchType.EAGER annotation, but the data doesn't appear when I write the MediaRepository. If I don't implement that file, the media relationship and data comes back in the response. With MediaRepository.java Implemented, GET /pets returns: { "id": 72, "name": "Spot", "description": "Annoying as hell", "media": [], <-- why is this here only if I don't implement MediaRepository? ... } Without MediaRepository.java Implemented, GET

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

Spring data REST findBy nested entity

◇◆丶佛笑我妖孽 提交于 2019-12-05 10:42:49
I have a Spring Boot project using Spring-data-rest for generating my REST interface and I am trying to allow pagination for nested resources. I followed this workaround and got stuck with implementing the findBy query. I have the following Device entity: @Entity @Table(name = "devices") public class Device extends ResourceSupport { ... @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; } I need to query it using userId: @RequestMapping(path = "/users/{id}/devices", method = RequestMethod.GET) public ModelAndView getUserDevices(@PathVariable Integer id) {

Spring Data Rest - Proxy path not including link path

三世轮回 提交于 2019-12-05 09:22:18
I'm proxying a Spring REST backend like so: Backend: http://backend:8080 Proxied localhost: localhost:3000/api/backend -> http://backend:8080 If I browse locally to a proxied endpoint, it will proxy the request, the links, however, do not include the proxy path, i.e. GET localhost:3000/api/backend/people "href": "http://localhost:3000/people" I would expect this to be: "href": "http://localhost:3000/api/backend/people" There any way to fix this? Thanks! You should have a look at the x-forwarded-* headers your proxy is adding to the request. If the request from your proxy to the backend