How to set the default media type for spring-data-rest?

membersound

From RepositoryRestConfiguration I can see that setting spring.data.rest.default-media-type=application/json could change the default media type served by @RepositoryRestResource.

@SuppressWarnings("deprecation")
public class RepositoryRestConfiguration {
    private MediaType defaultMediaType = MediaTypes.HAL_JSON;
}

Question: as this class is in deprecation, what is the correct way to set/override the default type?

Andrew Mairose

You can do this via RepositoryRestConfiguration or simply with a property in your application.properties. See the documentation here.

The RepositoryRestConfiguration class is NOT deprecated. There are methods within it that are deprecated. The @SuppressWarnings("deprecation") annotation on the class does not mean that the class itself is deprecated. That is simply an annotation used to tell an IDE to not display deprecation warnings in the IDE.

The easiest way to do this would be in application.properties. However, you have the property name wrong. You wouldn't set it as spring.data.rest.default-media-type. The actual property it would expect is spring.data.rest.defaultMediaType. So in your application.properties, you could have:

spring.data.rest.defaultMediaType=application/json

With the RepositoryRestConfiguration, you could accomplish the same as such:

@Configuration
class CustomRestMvcConfiguration {

  @Bean
  public RepositoryRestConfigurer repositoryRestConfigurer() {

    return new RepositoryRestConfigurerAdapter() {

      @Override
      public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
        config.setDefaultMediaType(MediaType.APPLICATION_JSON);
      }
    };
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to disable the default exposure of Spring Data REST repositories?

From Dev

How to set media type with Python requests?

From Dev

How to set media type of a webservice response in springboot?

From Dev

415 Unsupported Media Type with Spring MVC and Rest Service

From Dev

Spring Rest Service that returns different media type based on logic

From Dev

Spring Rest Service that returns different media type based on logic

From Dev

Spring Data Rest - Parameters with default values

From Dev

Spring Data Rest Overriding Default GET verb

From Dev

How to set Default Profile Spring

From Dev

Set default content type header of Spring RestTemplate

From Dev

REST Media Type Proliferation

From Dev

Custom default headers for REST API only using Spring Data REST

From Dev

Spring Data MongoDB default type for inheritance

From Dev

How to set default auto mount options for removable media?

From Dev

Spring Data REST - projection of association of the abstract type

From Dev

How to set default content of input of type month?

From Dev

how to set default value for text type in mysql

From Dev

How to set the default value of enum type variable?

From Dev

How to set default currency type in Libre office

From Dev

Unsupported media type for REST POST

From Dev

Media type in REST API for validation

From Dev

Spring Boot - How to set the default schema for PostgreSQL?

From Dev

how to set the data type of mongoexport

From Dev

How To Set Cell Data Type

From Dev

how to set the data type of mongoexport

From Dev

Spring Data REST, MVC QueryDSL bindings | simulate default bindings

From Java

How to set base url for rest in spring boot?

From Dev

Getting 415 Unsupported Media Type while trying to upload a file in Spring Rest api

From Dev

415 unsupported media type + spring

Related Related

  1. 1

    How to disable the default exposure of Spring Data REST repositories?

  2. 2

    How to set media type with Python requests?

  3. 3

    How to set media type of a webservice response in springboot?

  4. 4

    415 Unsupported Media Type with Spring MVC and Rest Service

  5. 5

    Spring Rest Service that returns different media type based on logic

  6. 6

    Spring Rest Service that returns different media type based on logic

  7. 7

    Spring Data Rest - Parameters with default values

  8. 8

    Spring Data Rest Overriding Default GET verb

  9. 9

    How to set Default Profile Spring

  10. 10

    Set default content type header of Spring RestTemplate

  11. 11

    REST Media Type Proliferation

  12. 12

    Custom default headers for REST API only using Spring Data REST

  13. 13

    Spring Data MongoDB default type for inheritance

  14. 14

    How to set default auto mount options for removable media?

  15. 15

    Spring Data REST - projection of association of the abstract type

  16. 16

    How to set default content of input of type month?

  17. 17

    how to set default value for text type in mysql

  18. 18

    How to set the default value of enum type variable?

  19. 19

    How to set default currency type in Libre office

  20. 20

    Unsupported media type for REST POST

  21. 21

    Media type in REST API for validation

  22. 22

    Spring Boot - How to set the default schema for PostgreSQL?

  23. 23

    how to set the data type of mongoexport

  24. 24

    How To Set Cell Data Type

  25. 25

    how to set the data type of mongoexport

  26. 26

    Spring Data REST, MVC QueryDSL bindings | simulate default bindings

  27. 27

    How to set base url for rest in spring boot?

  28. 28

    Getting 415 Unsupported Media Type while trying to upload a file in Spring Rest api

  29. 29

    415 unsupported media type + spring

HotTag

Archive