package com.microservices.mon.k8s.utils;

import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class YamlConfig implements WebMvcConfigurer {

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.add(new YamlJackson2HttpMessageConverter());
    }

    public static class YamlJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter {
        public YamlJackson2HttpMessageConverter() {
            super(new YAMLMapper(), new org.springframework.http.MediaType("application", "yaml"));
        }
    }
}