package shop.alien.gateway.config;

import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

import java.util.ArrayList;
import java.util.List;

/**
 * Feign HttpMessageConverters 配置
 * 在 WebFlux 环境中，Spring Boot 可能不会自动配置 HttpMessageConverters，
 * 但 OpenFeign 仍然需要它来进行消息转换
 *
 * @author system
 * @date 2025-01-XX
 */
@Configuration
public class FeignHttpMessageConvertersConfig {

    /**
     * 手动创建 HttpMessageConverters bean，确保 OpenFeign 能够正常使用
     * 这个 bean 会被 OpenFeign 的 SpringDecoder 使用
     */
    @Bean
    public HttpMessageConverters httpMessageConverters() {
        List<HttpMessageConverter<?>> converters = new ArrayList<>();
        converters.add(new MappingJackson2HttpMessageConverter());
        return new HttpMessageConverters(converters);
    }
}


