SpringBoot-引入jackson-dataformat-xml之后,本返回json的接口返回xml

一、问题

当我们项目中需要引入"jackson-dataformat-xml"后,我们会发现我们原本返回json数据的接口也开始返回xml数据格式了

二、原因

public abstract class AbstractMessageConverterMethodProcessor extends AbstractMessageConverterMethodArgumentResolver
        implements HandlerMethodReturnValueHandler {
   
        /**
     * Writes the given return type to the given output message.
     * @param value the value to write to the output message
     * @param returnType the type of the value
     * @param inputMessage the input messages. Used to inspect the {@code Accept} header.
     * @param outputMessage the output message to write to
     * @throws IOException thrown in case of I/O errors
     * @throws HttpMediaTypeNotAcceptableException thrown when the conditions indicated
     * by the {@code Accept} header on the request cannot be met by the message converters
     */
    @SuppressWarnings({
   "rawtypes", "unchecked"})
    protected <T> void writeWithMessageConverters(@Nullable T value, MethodParameter returnType,
            ServletServerHttpRequest inputMessage, ServletServerHttpResponse outputMessage)
            throws IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException {
   

        ... 省略部分代码
      
        List<MediaType> mediaTypesToUse;

        MediaType contentType = outputMessage.getHeaders().getContentType();
        if (contentType != null && contentType.isConcrete()) {
   
            mediaTypesToUse = Collections.singletonList(contentType);
        }
        else {
   
            HttpServletRequest request = inputMessage.getServletRequest

你可能感兴趣的:(xml,java,java,xml,json)