package com.sikey.wa04.business.infrastructure.configuration;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sikey.wa04.common.dto.deserializer.MessageTypeDeserializer;
import com.sikey.wa04.common.dto.deserializer.MessageTypeSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

@Configuration
public class JacksonConfig {

    @Bean
    public ObjectMapper objectMapper() {
        ObjectMapper mapper = new Jackson2ObjectMapperBuilder()
                .createXmlMapper(false)
                .failOnEmptyBeans(false)
                .failOnUnknownProperties(false)
                .build();
        mapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);

        // MessageType Serializer/Deserializer
        MessageTypeSerializer messageTypeSerializer = new MessageTypeSerializer();
        MessageTypeDeserializer messageTypeDeserializer = new MessageTypeDeserializer();
        messageTypeSerializer.registerModule(mapper);
        messageTypeDeserializer.registerModule(mapper);

        return mapper;
    }

}
