Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/europeana/set-api.git in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
gsergiu committed Feb 22, 2023
2 parents e76d60f + 1649c76 commit e365d95
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class WebMvcConfig implements WebMvcConfigurer {

List<MediaType> supportedMediaTypes = new ArrayList<MediaType>();
Map<String, MediaType> mediaTypesMaping = new HashMap<String, MediaType>();

private static final MediaType APPLICATION_JSONLD = new MediaType("application", "ld+json");
private static final String EXTENSION_JSONLD = "jsonld";

/**
* Setup CORS for all GET, HEAD and OPTIONS, requests.
Expand Down Expand Up @@ -80,16 +83,19 @@ public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
// work in future
// releases
configurer.favorPathExtension(true);

// use application/ld+json if no Content-Type is specified
configurer.defaultContentType(MediaType.APPLICATION_JSON);
configurer.defaultContentType(MediaType.valueOf(HttpHeaders.CONTENT_TYPE_JSONLD));

configurer.mediaTypes(getMediaTypesMapping());
}

private Map<String, MediaType> getMediaTypesMapping() {
if (mediaTypesMaping.isEmpty()) {
for (MediaType mediaType : supportedMediaTypes) {
if(APPLICATION_JSONLD.equals(mediaType)){
mediaTypesMaping.put(EXTENSION_JSONLD, mediaType);
}
mediaTypesMaping.put(mediaType.getSubtype(), mediaType);
}
}
Expand All @@ -108,7 +114,7 @@ public HttpMessageConverter<String> getStringHttpMessageConverter() {

private List<MediaType> getSupportedMediaTypes() {
if (supportedMediaTypes.isEmpty()) {
supportedMediaTypes.add(new MediaType("application", "ld+json"));
supportedMediaTypes.add(APPLICATION_JSONLD);
supportedMediaTypes.add(MediaType.APPLICATION_JSON);
supportedMediaTypes.add(MediaType.APPLICATION_XML);
supportedMediaTypes.add(MediaType.TEXT_PLAIN);
Expand Down

0 comments on commit e365d95

Please sign in to comment.