package com.usky.alarm.service.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.http.converter.ObjectToStringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author yq
 */
@Configuration
public class FormatterConfiguration implements WebMvcConfigurer {

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new StringDateConverter());
    }

    @Bean
    public ObjectToStringHttpMessageConverter objectToStringHttpMessageConverter() {
        FormattingConversionService conversionService = new FormattingConversionService();
        conversionService.addConverter(new StringDateConverter());
        conversionService.addConverter(new DateStringConvert());
        ObjectToStringHttpMessageConverter httpMessageconverter = new ObjectToStringHttpMessageConverter(conversionService);
        return httpMessageconverter;
    }
}
