Posts

Showing posts with the label hateoas

Spring hateoas : Custom media type configuration

Custom media type implementations are picked up by Spring HATEOAS by scanning the application context for any implementations of the HypermediaMappingInformation interface. Each media type must implement this interface in order to: Be applied to WebClient, WebTestClient, or RestTemplate instances. Support serving that media type from Spring Web MVC and Spring WebFlux controllers. To define your own media type could look as simple as this: @Configuration class MyMediaTypeConfiguration implements HypermediaMappingInformation {   @Override   public List<MediaType> getMediaTypes() {     return MediaType.parse("application/vnd-acme-media-type")    }   @Override   public Module getJacksonModule() {     return new Jackson2MyMediaTypeModule();    }   @Bean   MyLinkDiscoverer myLinkDiscoverer() {     return new MyLinkDiscoverer();    } } The configuration class returns the media type it supports. This...