简体   繁体   中英

Spring Data REST: Custom Response

I have the following problem. I am currently working with spring, spring-data-jpa and spring-data-rest. I want to create an rest endpoint for my jpa repository.

So, my current response of my spring-data-rest endpoint is as follows:

{
  "_embedded": {
    "game": [
      
    ]
  },
  "_links": {
    "self": {
      "href": "http://localhost:8080/game"
    },
    "profile": {
      "href": "http://localhost:8080/profile/game"
    }
  },
  "page": {
    "size": 20,
    "totalElements": 0,
    "totalPages": 0,
    "number": 0
  }
}

My problem is, that I only want to return the game part in the _embedded part. No _links, no other things. How can I do that?

Does that answer your question?

You can use projection, Spring Data REST documentation :

But what if you do not want address details at all? Again, by default, Spring Data REST exports all of its attributes (except the id). You can offer the consumer of your REST service an alternative by defining one or more projections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM