Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ protected Map<String, MediaType> getDefaultMediaTypes() {
if (supportedMediaTypes.contains(MediaType.APPLICATION_CBOR)) {
map.put("cbor", MediaType.APPLICATION_CBOR);
}
if (supportedMediaTypes.contains(MediaType.APPLICATION_ATOM_XML)) {
if (supportedMediaTypes.contains(MediaType.APPLICATION_YAML)) {
map.put("yaml", MediaType.APPLICATION_YAML);
}
return map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import org.springframework.http.MediaType;
import org.springframework.http.converter.AbstractJacksonHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverters;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.xml.JacksonXmlHttpMessageConverter;
import org.springframework.stereotype.Controller;
import org.springframework.util.AntPathMatcher;
Expand Down Expand Up @@ -232,6 +234,32 @@ void contentNegotiationManager() {
.containsEntry("yaml", MediaType.APPLICATION_YAML);
}

@Test
void contentNegotiationManagerWithYamlConverterOnly() {
assertThat(mediaTypeMappingsFor(MediaType.APPLICATION_YAML))
.containsOnlyKeys("yaml")
.containsEntry("yaml", MediaType.APPLICATION_YAML);
}

@Test
void contentNegotiationManagerWithAtomConverterOnly() {
assertThat(mediaTypeMappingsFor(MediaType.APPLICATION_ATOM_XML))
.containsOnlyKeys("atom")
.containsEntry("atom", MediaType.APPLICATION_ATOM_XML);
}

private Map<String, MediaType> mediaTypeMappingsFor(MediaType mediaType) {
StringHttpMessageConverter converter = new StringHttpMessageConverter();
converter.setSupportedMediaTypes(List.of(mediaType));
WebMvcConfigurationSupport configuration = new WebMvcConfigurationSupport() {
@Override
protected void configureMessageConverters(HttpMessageConverters.ServerBuilder builder) {
builder.disableDefaults().addCustomConverter(converter);
}
};
return configuration.mvcContentNegotiationManager().getMediaTypeMappings();
}

@Test
void uriComponentsContributor() {
ApplicationContext context = initContext(WebConfig.class);
Expand Down