package cn.com.capcloud.core.system.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @Author LiaoJiaHui
 * @Create 2025/3/19
 */
@Configuration
@EnableWebMvc // 启用 Spring MVC 配置
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        // 如果请求体是字符串，添加 StringHttpMessageConverter
        converters.add(new StringHttpMessageConverter()); // 优先处理字符串

        // 添加 JSON 转换器
        converters.add(new MappingJackson2HttpMessageConverter()); // 后处理 JSON
    }

}
