0

I am using CrudRepository in spring boot application. It works fine but I am getting extra json attribute _links. How do I skip that extra json, as it's affecting on render large json object.

i am getting this kind of json format in response;

    {
  "_embedded": {
    "userses": [
      {
        "user_name": "john doe",
        "_links": {
          "self": {
            "href": "http://localhost:8080/userses/47375"
          },
          "users": {
            "href": "http://localhost:8080/userses/47375"
          }
        }
      },
      {
        "user_name": "john1 doe1",
        "_links": {
          "self": {
            "href": "http://localhost:8080/userses/21665"
          },
          "users": {
            "href": "http://localhost:8080/userses/21665"
          }
        }
      },
      {
        "user_name": "remmya1 decruize1",
        "_links": {
          "self": {
            "href": "http://localhost:8080/userses/47876"
          },
          "users": {
            "href": "http://localhost:8080/userses/47876"
          }
        }
      }
}

how do i neglect that extra part in json.

Suraj Bande
  • 89
  • 2
  • 9
  • Could you provide a bit more information, maybe some piece of code? Or an example of what you want as opposed to what you are getting? Look at [How do I ask a good question](https://stackoverflow.com/help/how-to-ask) – SBylemans Apr 04 '18 at 07:53
  • @SBylemans i have updated this post with the response i m getting as output. i guess it explains well my concern. – Suraj Bande Apr 04 '18 at 08:56
  • https://stackoverflow.com/questions/23264044/disable-hypertext-application-language-hal-in-json maybe this would be helpful in your case. – Yassine Ben Hamida Apr 04 '18 at 09:04
  • And how are you using `CrudRepository` to achieve this response? What object are you mapping it to? Usually `CrudRepository` is used as such `class MyObjectRepository implements CrudRepository {...}` where MyObject is the object to which the response is mapped. – SBylemans Apr 04 '18 at 09:05

1 Answers1

0

If you're using CrudRepository, you just need to adjust the object to which you are mapping it to. For instance, the way you used CrudRepository may be in this way:

class UserRepository implements CrudRepository<User,String> {...}

String is the class of the identifier (presumed user_name)

The User class could the be the following:

class User {
    @Id
    public String userName;
}

When returning this, the user will not contain the _links property.

SBylemans
  • 1,764
  • 13
  • 28