| New file |
| | |
| | | package cc.mrbird.febs.common.configure; |
| | | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Configuration |
| | | public class HttpMessageConverterConfigure { |
| | | |
| | | @Bean |
| | | public MappingJackson2HttpMessageConverter markdownHttpMessageConverter() { |
| | | MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); |
| | | |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | // 配置更宽松的 JSON 解析选项 |
| | | mapper.configure(com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true); |
| | | mapper.configure(com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true); |
| | | |
| | | converter.setObjectMapper(mapper); |
| | | converter.setDefaultCharset(StandardCharsets.UTF_8); |
| | | |
| | | // 支持 text/markdown 和 text/plain 类型 |
| | | List<MediaType> supportedMediaTypes = new ArrayList<>(); |
| | | supportedMediaTypes.add(MediaType.APPLICATION_JSON); |
| | | supportedMediaTypes.add(MediaType.TEXT_PLAIN); |
| | | supportedMediaTypes.add(new MediaType("text", "markdown", StandardCharsets.UTF_8)); |
| | | supportedMediaTypes.add(new MediaType("text", "html", StandardCharsets.UTF_8)); |
| | | |
| | | converter.setSupportedMediaTypes(supportedMediaTypes); |
| | | return converter; |
| | | } |
| | | } |