spring-data-rest

Selectively expand associations in Spring Data Rest response

别来无恙 提交于 2019-11-26 19:46:31
问题 I have a standard Spring data JPA and Spring data Rest setup which, correctly, returns associations as links to the correct resources. { "id": 1, "version": 2, "date": "2011-11-22", "description": "XPTO", "_links": { "self": { "href": "http://localhost:8000/api/domain/1" }, "otherDomain": { "href": "http://localhost:8000/api/domain/1/otherDomain" } } } However in some requests i would like to have the association to the "otherDomain" expanded (so the client does not have to do N+1 requests to

Disable Hypertext Application Language (HAL) in JSON?

余生颓废 提交于 2019-11-26 18:39:21
Using Spring Data REST with JPA in version 2.0.2.RELEASE. How can I disable Hypertext Application Language (HAL) in the JSON ? http://stateless.co/hal_specification.html I have tried many things already, but to no avail. For example, I have set Accept and Content-type headers to "application/json" instead of "application/hal+json" but I still receive the JSON content with hyper links. For example, I'd like to get something like: { "name" : "Foo", "street" : "street Bar", "streetNumber" : 2, "streetLetter" : "b", "postCode" : "D-1253", "town" : "Munchen", "country" : "Germany", "phone" : "+34

How to add links to root resource in Spring Data REST?

自作多情 提交于 2019-11-26 17:47:17
问题 How to expose an external resource (not managed through a repository) in the root listing of resources of Spring Data REST? I defined a controller following the pattern in Restbucks 回答1: This can be done by implementing ResourceProcessor<RepositoryLinksResource> . Following code snippet adds "/others" to the root listing @Controller @ExposesResourceFor(Other.class) @RequestMapping("/others") public class CustomRootController implements ResourceProcessor<RepositoryLinksResource> {

Spring Data REST @Idclass not recognized

点点圈 提交于 2019-11-26 16:32:38
问题 I have an entity named EmployeeDepartment as below @IdClass(EmployeeDepartmentPK.class) //EmployeeDepartmentPK is a serializeable object @Entity EmployeeDepartment{ @Id private String employeeID; @Id private String departmentCode; ---- Getters, Setters and other props/columns } and I have a Spring Data Repository defined as as below @RepositoryRestResource(....) public interface IEmployeeDepartmentRepository extends PagingAndSortingRepository<EmployeeDepartment, EmployeeDepartmentPK> { }

Why is an excerpt projection not applied automatically for a Spring Data REST item resource?

冷暖自知 提交于 2019-11-26 16:25:27
问题 I made a projection which should expose nested entities: @Projection(name = "inlineBusiness", types = { UserModel.class }) public interface InlineBusinessUserModelProjection { String getUsername(); String getFirstName(); String getLastName(); Date getBirthdate(); String getEmail(); BusinessModel getBusiness(); } And the service repository: @RepositoryRestResource(collectionResourceRel = "users", path = "users", excerptProjection = InlineBusinessUserModelProjection.class) public interface

How to consume Page<Entity> response using Spring RestTemplate

£可爱£侵袭症+ 提交于 2019-11-26 15:58:49
问题 I'm using spring data (mongoDb) and I've got my repository: public interface StoriesRepository extends PagingAndSortingRepository<Story, String> {} Then i have a controller: @RequestMapping(method = RequestMethod.GET) public ResponseEntity<Page<StoryResponse>> getStories(Pageable pageable) { Page<StoryResponse> stories = storiesRepository.findAll(pageable).map(StoryResponseMapper::toStoryResponse); return ResponseEntity.ok(stories); } Everything works fine, but I can't consume my endpoint

Expose all IDs when using Spring Data Rest

我是研究僧i 提交于 2019-11-26 14:20:52
问题 I'd like to expose all IDs using a Spring Rest interface. I know that per default an ID like this will not be exposed via the rest interface: @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(unique=true, nullable=false) private Long id; I'm aware that I can use this to expose the ID for User : @Configuration public class RepositoryConfig extends RepositoryRestMvcConfiguration { @Override protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {

How to Log HttpRequest and HttpResponse in a file?

这一生的挚爱 提交于 2019-11-26 11:36:13
问题 Can anyone explain any techniques to log HttpRequest and HttpResponse in a file. We are using Spring MVC/Spring Rest. What we want is to intercept the request before it is processed and log it. Same way intercept the response before it is sent and log it. Thanks a lot in advance. 回答1: For logging the request Spring has the AbstractRequestLoggingFilter class (well actually one of the subclasses). This can be used to log the incoming request (before and after processing). Depending on the

How to work with DTO in Spring Data REST projects?

一世执手 提交于 2019-11-26 11:04:01
问题 Spring Data REST automates exposing only domain object. But most often we have to deal with Data Transfer Objects. So how to do this in SDR way? 回答1: An approach of how to work with DTO in Spring Data REST projects The working example is here Entities Entities must implement the Identifiable interface. For example: @Entity public class Category implements Identifiable<Integer> { @Id @GeneratedValue private final Integer id; private final String name; @OneToMany private final Set<Product>

Can I make a custom controller mirror the formatting of Spring-Data-Rest / Spring-Hateoas generated classes?

北城以北 提交于 2019-11-26 10:23:48
问题 I\'m trying to do something I think should be really simple. I have a Question object, setup with spring-boot, spring-data-rest and spring-hateoas. All the basics work fine. I would like to add a custom controller that returns a List<Question> in exactly the same format that a GET to my Repository \'s /questions url does, so that the responses between the two are compatible. Here is my controller: @Controller public class QuestionListController { @Autowired private QuestionRepository