20

How exactly should Spring Data Rest be configured to return plain JSON instead of HAL (JSON with Hypermedia like links)

Related

CDT
  • 10,165
  • 18
  • 66
  • 97
Paul Verest
  • 60,022
  • 51
  • 208
  • 332

2 Answers2

16

Add the below property to your application.properties or yml . By default it is application/hal+json

spring.data.rest.defaultMediaType=application/json

Fahad Fazil
  • 638
  • 1
  • 9
  • 20
12

for me spring.data.rest.defaultMediaType=application/json does not take effect. But it can be approched by programmed config, like below :

    public class SpringRestConfiguration implements RepositoryRestConfigurer {
        @Override
        public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {

            config.setDefaultMediaType(MediaType.APPLICATION_JSON);
            config.useHalAsDefaultJsonMediaType(false);
        }
    }
shenyu1997
  • 602
  • 7
  • 5