Spring Data REST in plain JSON (not HAL format)

瘦欲@ 提交于 2019-11-29 03:34:50

问题


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

Related

  • Spring returns Resource in pure JSON not in HAL Format when including spring data rest
  • Spring Data Rest -Disable self links(HAL) in Json
  • and big Disable Hypertext Application Language (HAL) in JSON?
  • using jsonapi instead of HAL Changing the JSON format for spring-data-rest

回答1:


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

spring.data.rest.defaultMediaType=application/json




回答2:


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);
        }
    }


来源:https://stackoverflow.com/questions/37971312/spring-data-rest-in-plain-json-not-hal-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!