2

I've created a basic Spring Boot application with Restful services using CrudRepository to interact with the DB.

The JSON response contains "_embedded" : { ... } and "_links" : { ... } which I don't want.

{
  "_embedded" : {
    "countries" : [
      {
        "name" : "Antarctica",
        "_links" : {
          "self" : {
            "href" : "http://localhost:8080/world/rest/countries/ATA"
          },
          "country" : {
            "href" : "http://localhost:8080/world/rest/countries/ATA"
          }
        }
      },
      ...
    ]
  }

How can I get rid of this structure and return my objects in a simple list? Is there some property or configuration that can be set to remove this from all responses?

I've added the property spring.hateoas.use-hal-as-default-json-media-type=false, didn't work.

Tried converting the result to a list manually, countries.forEach(countriesList::add);; no luck..

POJO Class to map objects

/* Package and Imports */

@Entity(name = "country")
public class Country {

    @Id
    private String code;

    private String name;
    private String continent;
    private String region;

    /* Getters, Setters and equals method below */
}
LearningDeveloper
  • 638
  • 2
  • 11
  • 23

1 Answers1

3

After going through many topics on StackOverflow and other sites. I've come to the conclusion that I'm better off without the spring-boot-starter-data-rest.

  1. I've removed the spring-boot-starter-data-rest dependency from my pom.xml.
  2. Created a @RestController to handle requests.
  3. Created methods to handle different request types (GET, POST, etc.)

As suggested by @michalk

Disable Hypertext Application Language (HAL) in JSON?

This does help partially but not for arrays.

LearningDeveloper
  • 638
  • 2
  • 11
  • 23