| 1 | package edu.ucsb.cs.scaffold.config; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.databind.DeserializationFeature; | |
| 4 | import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; | |
| 5 | import java.util.List; | |
| 6 | import org.springframework.context.annotation.Configuration; | |
| 7 | import org.springframework.http.MediaType; | |
| 8 | import org.springframework.http.converter.HttpMessageConverter; | |
| 9 | import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; | |
| 10 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |
| 11 | ||
| 12 | /** | |
| 13 | * Registers a YAML HttpMessageConverter so that endpoints can accept {@code application/yaml} | |
| 14 | * request bodies (e.g. {@code POST /api/concept}). YAML block scalars make multi-line Markdown | |
| 15 | * fields far easier to enter through Swagger than JSON's escaped one-line strings. | |
| 16 | * | |
| 17 | * <p>The converter is <b>read-only</b> ({@code canWrite} is false): it only deserializes request | |
| 18 | * bodies. Responses continue to be serialized as JSON by the default converters, even for clients | |
| 19 | * that send {@code Accept: */*}. | |
| 20 | */ | |
| 21 | @Configuration | |
| 22 | public class YamlMessageConverterConfig implements WebMvcConfigurer { | |
| 23 | ||
| 24 | @Override | |
| 25 | public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { | |
| 26 | converters.add(new YamlHttpMessageConverter()); | |
| 27 | } | |
| 28 | ||
| 29 | static class YamlHttpMessageConverter extends AbstractJackson2HttpMessageConverter { | |
| 30 | YamlHttpMessageConverter() { | |
| 31 | // Unknown properties are ignored, matching Spring Boot's default JSON behavior. | |
| 32 | super( | |
| 33 | YAMLMapper.builder().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build(), | |
| 34 | MediaType.parseMediaType("application/yaml"), | |
| 35 | MediaType.parseMediaType("application/x-yaml"), | |
| 36 | MediaType.parseMediaType("text/yaml")); | |
| 37 | } | |
| 38 | ||
| 39 | @Override | |
| 40 | public boolean canWrite(Class<?> clazz, MediaType mediaType) { | |
| 41 |
1
1. canWrite : replaced boolean return with true for edu/ucsb/cs/scaffold/config/YamlMessageConverterConfig$YamlHttpMessageConverter::canWrite → KILLED |
return false; |
| 42 | } | |
| 43 | } | |
| 44 | } | |
Mutations | ||
| 41 |
1.1 |