0

i'm trying to get json response from my rest api but i'm getting this format !

I used @RestController annotation and i'm geting "_embedded" !! i don't know how to change that because in my front application i can't use this format !

      @RestController
      public class HeroRestController {


 @Autowired
 private HeroRepository HeroRepo;


 @GetMapping("/heroes")
    public List<Hero> getMessage(){
        return HeroRepo.findAll();
    }
}

What i'm getting :

    {
       "_embedded" : {
           "heroes" : [ {
              "name" : "hero11",
                "_links" : {
           "self" : {
       "href" : "http://localhost:8009/heroes/2"
        },
    "hero" : {
      "href" : "http://localhost:8009/heroes/2"
    }
  }
     }, {
      "name" : "hero22",
      "_links" : {
    "self" : {
      "href" : "http://localhost:8009/heroes/3"
    },
    "hero" : {
      "href" : "http://localhost:8009/heroes/3"
    }
  }
}
SS_FStuck
  • 231
  • 1
  • 5
  • 20

1 Answers1

0

SPRING HATEOAS (HateoasProperties)

Use spring.data.rest.defaultMediaType = application/json OR

spring.hateoas.use-hal-as-default-json-media-type=true in application.properties file. For more Spring data rest HATEOS , refer SPRING HATEOAS (HateoasProperties)

DEBENDRA DHINDA
  • 1,163
  • 5
  • 14
  • i got this format : { "links" : [ { "rel" : "self", "href" : "http://localhost:8009/heroes{?page,size,sort}", "hreflang" : null, "media" : null, "title" : null, "type" : null, "deprecation" : null }, { "rel" : "profile", "href" : "http://localhost:8009/profile/heroes", "hreflang" : null, "media" : null, "title" : null, "type" : null, "deprecation" : null }, { "rel" : "search", "href" : "http://localhost:8009/heroes/search", "hreflang" : null, "media" : null, "title" : null, "type" : null, "deprecation" : null } ], – SS_FStuck Oct 07 '19 at 12:47